3

I'm Using this bundle to manage my data

I'm able to create the document, but I can't retrieve them I tried with

    $dm = $this->container->get('doctrine_couchdb.odm.default_document_manager');
    $users = $dm->getRepository('myGarageBundle:Utente')->find("781f1ea2e6281beb4ee9ff72b6054af2");

and this retrieve one document like this:

object(my\GarageBundle\CouchDocument\Utente)[303]
  private 'id' => string '781f1ea2e6281beb4ee9ff72b6054af2' (length=32)
  private 'name' => string 'foo' (length=7)

And this is ok. But If i do

$users = $dm->getRepository('myGarageBundle:Utente')->findBy(array('name' => 'foo'));

I have got an empty Array.

My document in my couchDb is

{"_id":"781f1ea2e6281beb4ee9ff72b6054af2","_rev":"1-f89fc2372709de90ab5d1f6cfe6a8f47","type":"my.GarageBundle.CouchDocument.Utente","name":"foo"}
monkeyUser
  • 4,301
  • 7
  • 46
  • 95

1 Answers1

2

Check this page

Querying by simple conditions only works for documents with indexed fields.

you have to add this in your Entity

/**
 * @CouchDB\Index
 * @CouchDB\Field(type="string")
 */
private $name;

The Doctrine persistence interfaces ship with a concept called ObjectRepository that allows to query for any one or set of fields of an object. Because CouchDB uses views for querying (comparable to materialized views in relational databases) this functionality cannot be achieved out of the box. Doctrine CouchDB could offer a view that exposes every field of every document, but this view would only grow into infinite size and most of the information would be useless.

If you want use method like findAll() you have to Index all you document:

<?php
/** @Document(indexed=true) */
class Person
{
    /**
     * @Index
     * @Field(type="string")
     */
    public $name;
}
Barno
  • 3,271
  • 5
  • 28
  • 58