Php 基于所选类别子项获取实体

Php 基于所选类别子项获取实体,php,mysql,symfony,doctrine-orm,query-builder,Php,Mysql,Symfony,Doctrine Orm,Query Builder,我想获取与所选类别的子项相关的记录 例如,我们有这样一个类别树: id = 1, category_id = 2, title = This records must belong to ORANGE category! 主要内容: 水果 汽车 子项:父项Id不能为空!在本例中:父Id=1 苹果 橙色 香蕉 我们有这样一个实体数据库记录: id = 1, category_id = 2, title = This records must belong to ORANGE category!

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

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

id = 1, category_id = 2, title = This records must belong to ORANGE category!
主要内容:

水果 汽车 子项:父项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'));

它是如何失败的?您可以提供错误或异常消息,也可以提供main和children的映射。这些实体是不同的还是子实体引用了同一实体上的父实体?