這是我的情況:Grails一對多 - 映射級聯
一個叫做League的類和一個叫Team的關係1-N。
一個聯盟可以有多個球隊。 在單元測試中,我試圖指定:球隊A加入聯盟1並且比同一球隊A加入聯盟2.
發生什麼事是兩個聯盟都指向同一球隊A.但是球隊A只能聯盟2.
將聯盟1的引用刪除到A隊的最好方法是什麼?
編輯:
class League {
static hasMany = [ teams: Team, schedules: Schedule ]
String name
...
}
class Team {
static belongsTo = [ league: League ]
...
}
LeagueTest
def league1 = new League(name: "Serie A")
def league2 = new League(name: "Premier League")
def team = new Team(name: 'AC Milan', stadium: 'San siro', nation: 'Italy')
league1.addToTeams(team)
assert league1.numOfTeams() > league2.numOfTeams() //true
league2.addToTeams(team)
assert league1.numOfTeams() == league2.numOfTeams() //true
assert team.league == league2 //true
assert team.league == league1 //false
怎樣的關係看在你域級? (belongsTo,hasMany是我指的) – marko 2012-08-13 08:07:11
請顯示您的代碼。爲什麼你將一個團隊分配給兩個聯盟? – 2012-08-13 13:01:45