簡體   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