我有一个看起来像这样的域模型
Category 1 ------- * Type 1 ------- * Expense
或者用英文“一个费用有一个类型,每个类型都属于一个类别”。我想编写一个 Criteria 查询来查找特定类别中的所有费用。我试过这两个
Expense.withCriteria {
eq('type.category', someCategoryInstance)
}
和这个
Expense.withCriteria {
type {
eq('category', someCategoryInstance)
}
}
但是它们都不起作用,我错过了什么?
更新
我被要求显示域类,所以它们是:
public class Category {
String description
static hasMany = [types: Type]
}
public class Type {
String description
static hasMany = [expenses: Expense]
static belongsTo = [category: Category]
}
public class Expense {
static belongsTo = [type: Type]
Date date
String description
float amount
}