Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2 MongoDB get child records of object
    primarykey
    data
    text
    <p>i'm using doctrine/mongodb-odm-bundle and i have a problem: I can't get referenced rows from document (or i just don't know how to do this..) i have 2 documents with one-to-many reference like this: first<br/></p> <pre><code>/** * @MongoDB\Document(collection="categories") */ class Category { /** * @var integer $id * * @MongoDB\Id(strategy="auto") */ private $id; /** * @var string $name * * @MongoDB\String * @Assert\NotBlank() * @Assert\MinLength(3) */ private $name; /** * @MongoDB\ReferenceMany(targetDocument="Application\Bundle\DefaultBundle\Document\Wallpaper", mappedBy="category") */ private $files; ................. /** * Set files * * @param array $files */ public function setFiles($files) { $this-&gt;files = $files; } /** * Get files * * @return array $files */ public function getFiles() { return $this-&gt;files; } </code></pre> <p>................. <br/> second</p> <pre><code>/** * @MongoDB\Document(collection="wallpapers") */ class Wallpaper { /** * @var string $id * @MongoDB\Id(strategy="auto") */ protected $id; /** * @MongoDB\ReferenceOne(targetDocument="Application\Bundle\DefaultBundle\Document\Category", inversedBy="files") */ private $category; /** * Get category * * @return Application\Bundle\DefaultBundle\Document\Category $category */ public function getCategory() { return $this-&gt;category; } /** * Set category * * @param Application\Bundle\DefaultBundle\Document\Category $category */ public function setCategory($category) { $this-&gt;category = $category; } } </code></pre> <p>here is code from controller:</p> <pre><code>$category = $dm-&gt;getRepository('ApplicationDefaultBundle:Category')-&gt;findOneBy(...); $wallpapers = $category-&gt;getFiles(); </code></pre> <p>$wallpapers and $document->files are NULL. how i can retrieve records related to category? and how can i get category from concrete wallpaper object? is there any "JOIN" analog like in standard ORM?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload