在Grails/Gorm中,我正在存储一个物理站点,在定义的位置中保存对象。
域类只需:
例A
现场直流
..。但是对象改变了它们的位置,以后我需要能够看到在给定的时间(什么时候),哪些位置被什么占据了。
因此,我添加了另一个域类。
例B
位置直流
现场直流
因为所有的对象都有一个描述,并且会有大量的站点使用相同的对象,所以我添加了一个域类来保存每个对象。结果:
示例C
目标直流
位置直流
)
现场直流
现在地图,对我来说,似乎不再合理。
我正在考虑删除映射,代之以另一个域类:
示例D
目标直流
目标对位置直流
)
位置直流
现场直流
问题
在database?
编辑:基于ROBS答案的一种新方法
在你的建议的启发下,罗布,我起草了这个数据模型,赋予"SeasonPlan“(修正的"ResidenceHistory")一个”前排“角色。
class Zoo {
static hasMany = [seasons: SeasonPlan]
String name
}
// one way of representing histories
class SeasonPlan = {
static belongsTo = [zoo: Zoo] // a SeasonPlan belongs to a single particular Zoo
static hasMany = [cages: Cage]
DateTime from
DateTime until
}
class Cage {
static belongsTo = [seasonPlan: SeasonPlan] // a cage belongs to a single seasonplan
Species species // a cage has a single Species
Integer cageNumber
}
class Species {
// static hasMany = [cages: Cage] // commented out - no reverse-lookup necessary
String name
}这有一个缺点:每个赛季的计划都有一个新的笼子--尽管在现实中,笼子是一样的!(想象一下"Cage“中的"Integer squareMeters”,以便更清楚地说明为什么不需要这样做。)
对我来说,将这样的东西应用到数据模型中常常很难理解--,我如何将像这样的“伪静态”数据安装到应用程序中,同时保持现实世界中的相关性?。
我希望我的意思是可以理解的-抱歉,如果不是。
发布于 2011-01-10 13:22:49
我还在努力理解你的领域,你可能把事情搞得太复杂了。这个基本的模型能起作用吗?如果没有,你能解释原因吗?如果我能更好地理解你的情况,我会更新我的例子。
编辑-更新的例子给出下面的评论。
class Cage {
static belongsTo = [zoo: Zoo] // a cage belongs to a single particular Zoo
Species species // a cage has a single Species
String name
}
class Zoo {
static hasMany = [cages: Cage]
String name
}
class Species {
static hasMany = [cages: Cage] // a species can be in many different cages
String name
}
// one way of representing histories
class ResidenceHistory = {
Species species
Cage cage
DateTime from
DateTime until
}下面是如何使用域的方法:
def sanDiego = new Zoo(name: 'San Diego Zoo').save()
def aviary = new Cage(name: 'Aviary', zoo: sanDiego).save()
def elephantCage = new Cage(name: 'Elephant Area, Cage 5', zoo: sanDiego).save()
def bird = new Species(name: 'Blue-Footed Booby', cage: aviary).save()
def elephant = new Species(name: 'Asian Elephant', cage: elephantCage).save()
new ResidenceHistory(species: bird, cage: aviary, from: new DateTime(), to: new DateTime().plusDays(20)).save()要回答您列出的问题,具体如下:
这取决于
https://stackoverflow.com/questions/4646855
复制相似问题