doctrine / mongodb-odm-bundleを使用していますが、問題があります。ドキュメントから参照行を取得できません(または、これを行う方法がわかりません)。1対1のドキュメントが2つあります。このような多くの参照:最初に
/**
* @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はNULLです。カテゴリに関連するレコードを取得するにはどうすればよいですか?コンクリートの壁紙オブジェクトからカテゴリを取得するにはどうすればよいですか?標準のORMのような「JOIN」アナログはありますか?