[英]Avoiding join table in grails
考慮以下簡化情況:我的產品可以具有服務器屬性,並且屬性值取決於國家/地區。
當我以標准方式對屬性域類進行建模時,如下所示。 這意味着屬性可以具有取決於國家的值,並且值可以屬於不同的屬性。 n:m關系產生一個單獨的聯接表。
class Attribute {
String id
String name
static hasMany = [attributeValues: AttributeValue]
static mapping = {
attributeValues joinTable: [name: 'attribute_values', key: 'attribute_id']
}
}
class AttributeValue {
String id
Locale language
String value
}
現在的問題是,是否可以在沒有連接表的情況下在GORM中對此建模?
使用SQL native,這沒有問題。 在數據庫中,這將導致如下所示的結構。 連接應從列attribute.attribute_key到列attribute_value.attribute_key
數據庫中的聯接表
create view JOIN_ATTRIBUTE_VALUE_V as
(!!the sql u select upown!!)
然后創建grails.domain類
class joinAttributeValueV {
String id
String attributeKey
Locale language
String value
static mapping = {
table 'JOIN_ATTRIBUTE_VALUE_V'
id column:"id" ,comment:""
attributeKey column:"ATTRIBUTE_KEY" ,comment:""
language column:"LANGUAGE" ,comment:""
value column:"VALUE" ,comment:""
}
}
使用GORM獲取域類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.