2015-06-10 51 views
0

的財產我有這樣的:withCriteria「或」像其他表

results = Quotation.withCriteria { 
    resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP) 
      createAlias("client","cte") 
      createAlias("client.assessor","asr") 
     or{ 
      ilike("asr.name", "%${params.find}%") 
      ilike("cte.name", "%${params.find}%") 
     } 
     projections { 
      groupProperty "id","id" 
      groupProperty "cte.name", "client" 
      groupProperty "asr.name", "employee" 
     } 
} 

但空車返回,我認爲這是由協會(客戶端和client.assessor),我需要根據客戶姓名或評估員進行搜索名稱,但這是來自其他表/ obj的屬性。

回答

0

更改createAlias到

def results = Quotation.withCriteria { 
    resultTransformer CriteriaSpecification.ALIAS_TO_ENTITY_MAP 
    createAlias "client","cte" 
    createAlias "cte.assessor","asr" /* <--- HERE ^^ */ 

    or { 
     ilike "asr.name", "%${params.find}%" 
     ilike "cte.name", "%${params.find}%" 
    } 
    projections { 
     groupProperty "id","id" 
     groupProperty "cte.name", "client" 
     groupProperty "asr.name", "employee" 
    } 
} 
+0

和美化你的代碼刪除所有這些括號。我的意思是,這是我們應該喜歡groovy/Grails的一個很好的理由! (; –