[英]How to get Entities based on field values in another Entitiy in Doctrine2?
[英]Doctrine Get Entities Based on Selected Category Children
我想获取与所选类别的孩子相关的记录。
例如,我们有一个这样的类别树:
主要:
子代:(父ID不能为空!在此示例中:父ID = 1)
我们有一个这样的实体(数据库记录):
id = 1, category_id = 2, title = This records must belong to ORANGE category!
当我们从数据库中选择“水果”类别时,我必须获得与“水果”本身及其子类别相关的实体。
我尝试了什么?
$qb
->select('i.id, i.title, i.slug, i.created_at, c.file')
->from('CSImageBundle:Image', 'i')
->leftJoin('i.taxonomies', 'tx')
->leftJoin('tx.children', 'st')
->where($qb->expr()->in('tx.id', 'st.id'));
失败...
我该怎么办?
很难说出没有错误消息,但是看起来好像是您选择的一个问题,c.file在哪里?
$qb
->select('i.id, i.title, i.slug, i.created_at, c.file') //should this be i.file? or tx.file? or st.file?
->from('CSImageBundle:Image', 'i')
->leftJoin('i.taxonomies', 'tx')
->leftJoin('tx.children', 'st')
->where($qb->expr()->in('tx.id', 'st.id'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.