我想获取与所选类别的子项相关的记录。
例如,我们有一个这样的类别树:
Main:
- 水果
- 汽车
子级:(父级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'));