![](/img/trans.png)
[英]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.