我剛開始探索Symfony2,我驚訝它有多少偉大的功能。我開始做博客教程在: http://tutorial.symblog.co.uk/
但使用的2.0主義加入旁路延遲加載
我的問題2.1版本,而不是是我的博客以下實體:
/**
* @ORM\OneToMany(targetEntity="Comment", mappedBy="blog")
*/
protected $comments;
,並在註釋實體如下:
/**
* @var string $blog
*
* @ORM\ManyToOne(targetEntity="Blog", inversedBy="comments")
* @ORM\JoinColumn(name="blog_id", referencedColumnName="id")
*/
private $blog;
我創建的功能,以獲得最新的博客和加盟,使我沒有爲每個博客延遲加載評論意見,並避免評論TABL多個呼叫Ë像這樣:
$qb = $this->createQueryBuilder('b')
->select('b')
->leftJoin('b.comments', 'c')
->addOrderBy('b.created', 'DESC');
,但是當我在樹枝模板運行該查詢的結果是:blog.comments
我得到的第一個查詢檢索博客與它的加入,但隨後而不是使用業增加值的修正對於評論我得到了每個博客條目的評論表的電話?我如何繞過該功能的特定情況下,但保持關係,所以我可以從視圖博客頁面獲得博客的所有評論?
maerlyn答案是正確的 – DonCallisto 2012-07-26 07:04:45