我使用教義/ mongodb-odm-bundle,我有一個問題:我無法從文檔中獲取引用行(或者我不知道如何執行此操作。 。) 我有2個文件用一個到許多參考這樣的: 第一
學說2 MongoDB獲取對象的子記錄
/**
* @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;
}
.................
第二
/**
* @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;
}
}
這是來自控制器的代碼:
$category = $dm->getRepository('ApplicationDefaultBundle:Category')->findOneBy(...);
$wallpapers = $category->getFiles();
$ wallpapers和$ document-> files are NULL。我如何檢索與類別相關的記錄?以及如何從混凝土牆紙對象中獲取類別?是否有像標準ORM中的「JOIN」模擬?