私はデータベースを設計するときに使用します。一般的なフィールドを埋め込むために埋め込みを使用しますが、initCreatedとcreatedByはできません。ドメインを拡張するか、埋め込みは一般的なフィールドを処理する正しい方法ですか? コードを入力してくださいドメインに共通のフィールドがいくつかあり、ドメイン拡張または埋め込みですか?
class Created {
Date dateCreated
Long createdBy
def beforeInsert()
{
dateCreated= new Date()
createdBy=0
}
}
class Updated {
Date lastUpdated
Long updatedBy
//it works?
def beforeUpdate(){
lastUpdated=new Date()
updatedBy=0
}
//it works?
def beforeInsert(){
lastUpdated=new Date()
updatedBy=0
}
}
class CreatedUpdated {
Created created
Updated updated
//Must use the embedded option, or the type of exception, can not find CreatedUpdated
static embedded = ['created','updated']
}
class Term {
String name
CreatedUpdated createdUpdated
static embedded = ['createdUpdated']
Term parent
static hasMany =[terms:Term]
static mapping = {
version false
}
String toString()
{
name
}
static constraints = {
name unique:true,size: 1..20
parent nullable: true
createdUpdated display:false,nullable:true
terms display:false
url url: true
}
}
または使用しますか?
class Term extends CreatedUpdated{
String name
Term parent
static hasMany =[terms:Term]
static mapping = {
version false
}
String toString()
{
name
}
static constraints = {
name unique:true,size: 1..20
parent nullable: true
terms display:false
url url: true
}
}
`
右私には何ですか?
thanks.audit-trail pluginは良いです。私はこの質問をする理由は誰もが私が思う態度を持っているわけではありません – sjbwylbs