Grails hasOne和许多相同的域 [英] Grails hasOne and hasMany same domain
本文介绍了Grails hasOne和许多相同的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的域名:
class Team {
hasOne [leader:Person]
hasMany [member:Person]
}
class Person {
belongsTo [team:Team]
}
但是当生成表时,组表中没有像leader_id这样的列。因此,领导关系并没有持续下去。
我应该如何解决这个问题?
解决方案
我需要的是
class Team {
belongsTo [leader:Person]
hasMany [成员:Person ]
}
class Person {
belongsTo [team:Team]
}
,以便Team表可以将所需的领导者引用返回给Person。
I have domain like this:
class Team {
hasOne [leader: Person]
hasMany [member: Person]
}
class Person {
belongsTo [team: Team]
}
But when the tables are generated, there is not a column like leader_id in the team table. And thus the leader relation is not persisted.
How should I fix it?
解决方案
I figured that, what I need is
class Team {
belongsTo [leader: Person]
hasMany [member: Person]
}
class Person {
belongsTo [team: Team]
}
so that the Team table can have the desired "leader" reference back to Person.
这篇关于Grails hasOne和许多相同的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文