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
/**
* @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->files = $files;
}
/**
* Get files
*
* @return array $files
*/
public function getFiles()
{
return $this->files;
}
.................
second
/**
* @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->category;
}
/**
* Set category
*
* @param Application\Bundle\DefaultBundle\Document\Category $category
*/
public function setCategory($category)
{
$this->category = $category;
}
}
here is code from controller:
$category = $dm->getRepository('ApplicationDefaultBundle:Category')->findOneBy(...);
$wallpapers = $category->getFiles();
$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?