教义 - 实体不被抓取 [英] Doctrine - entities not being fetched

查看:93
本文介绍了教义 - 实体不被抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些实体有一对多/多对一的关系 -

I have some entities with a one-to-many / many-to-one relationship -

生产课 -

/**
 * @OneToMany(targetEntity="ProductionsKeywords", mappedBy="production")
 */
protected $productionKeywords;

ProductionsKeywords课 -

ProductionsKeywords class -

/**
 * @ManyToOne(targetEntity="Production", inversedBy="productionKeywords")
 * @JoinColumn(name="production_id", referencedColumnName="id", nullable=false)
 * @Id
 */
protected $production;


/**
 * @ManyToOne(targetEntity="Keyword", inversedBy="keywordProductions")
 * @JoinColumn(name="keyword_id", referencedColumnName="id", nullable=false)
 * @Id
 */ 
protected $keyword;

关键字类 -

/**
 * @OneToMany(targetEntity="ProductionsKeywords", mappedBy="keyword")
 */
protected $keywordProductions;

如果我写了一个DQL查询,如

If I write a DQL query like

$query = $this->entityManager->createQuery("SELECT p FROM \Entity\Production p");

制作,生产关键字和关键字都正常,但是如果我尝试提取加入关键字和关键字像

The productions, productionKeywords and keywords all load fine, however if I try to fetch join the productionKeywords and keywords like

$query = $this->entityManager->createQuery("SELECT p, pk, k FROM \EntityProduction p 
                         LEFT JOIN p.productionKeywords pk
                         LEFT JOIN pk.keyword k
                         ");

然后实体未加载。
不知道我做错了什么,因为我和其他实体有相同的关系设置,它可以正常工作。

then the entities are not loaded. Not sure what I'm doing wrong as I have the same relationship setup with some other entities and it works fine with them.

推荐答案

OK,所以看来如果你有一个'pure'连接实体(如上面的ProductionsKeywords类),那么它不能在一个fetch查询中使用。通过在productions_keywords表格中使用时间戳列作为ProductionsKeywords类中的另一个属性,然后抓取连接开始工作,我遇到了这个问题。

OK, so it seems that if you have a 'pure' join entity (like the ProductionsKeywords class above) then it can't be used in a fetch query. I got around the issue by using a timestamp column in the productions_keywords table as another property in the ProductionsKeywords class and then the fetch joins began to work.

这篇关于教义 - 实体不被抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆