我有一個名爲People的Grails域,我想檢查每個人是否有子女。孩子是其他人物。這是我的域名結構:Grails域中的瞬態屬性
class People implements Serializable {
static constraints = {
name (nullable : false, unique : true)
createdBy (nullable : false)
creationDate (nullable : false)
}
static transients = ['hasChild']
static mapping = {
table 'PEOPLE'
id generator: 'sequence', params : [sequence : 'SEQ_PK_ID']
columns {
id column : 'APEOPLE_ID'
parentPeople column : 'PARENT_PEOPLE_ID'
}
parentPeople lazy : false
}
People parentPeople
String name
String description
Boolean hasChild() {
def childPeoples = People.createCriteria().count {
eq ('parentPeople', People)
}
return (childPeoples > 0)
}
}
但我不能在任何地方調用people.hasChild()。你能幫我解決這個問題嗎?非常感謝!
可以執行制定者呢? – 2012-12-21 18:33:22