繁体   English   中英

基于选定类别子项的学说获取实体

[英]Doctrine Get Entities Based on Selected Category Children

我想获取与所选类别的孩子相关的记录。

例如,我们有一个这样的类别树:

主要:

  1. 水果
  2. 汽车

子代:(父ID不能为空!在此示例中:父ID = 1)

  1. 苹果
  2. 橙子
  3. 香蕉

我们有一个这样的实体(数据库记录):

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM