Get CouchDb document form using DoctrineODM

I am using bundle to manage my data

I can create a document, but I cannot load them I tried with

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

      

and this returns one document like this:

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

      

And that's okay. But if I do

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

      

I have an empty array.

My document in my couchDb

{"_id":"781f1ea2e6281beb4ee9ff72b6054af2","_rev":"1-f89fc2372709de90ab5d1f6cfe6a8f47","type":"my.GarageBundle.CouchDocument.Utente","name":"foo"}

      

+3


source to share


1 answer


Check the page

Query using simple conditions only works for documents with indexed fields.

you have to add this to your Entity

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

      



Doctrine persistence interfaces come with a concept called ObjectRepository, which allows you to query an object for any one or multiple fields. Because CouchDB uses views for queries (comparable to materialized views in relational databases) this functionality cannot be achieved out of the box. Doctrine CouchDB can offer a view that reveals every area of ​​every document, but that view will only grow to infinite size and most of the information is useless.

If you want to use a type method findAll()

, you need to specify all documents:

<?php
/** @Document(indexed=true) */
class Person
{
    /**
     * @Index
     * @Field(type="string")
     */
    public $name;
}

      

+2


source







All Articles