withCriteria“或”喜欢其他表的属性

时间:2015-06-10 23:55:43

标签: hibernate grails gorm

我有这个:

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和client.assessor),我需要按客户名称或评估者名称进行搜索,但这是来自其他表/ obj的属性。

1 个答案:

答案 0 :(得分: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"
    }
}