Java Reference
In-Depth Information
part of this class is the belongsTo keyword, which implies a cascade delete relationship
between quests andtasks. Ifa Quest isdeleted, all its associated Task sare removed from
the database as well.
Knight s are associated with both Quest s and Castle s, but not through a cascade de-
lete. In fact, a Knight can be between Quest s and not belong to a Castle , so both
references are listed as nullable in the next listing.
Listing 10.14. The Knight class, which is associated with a Quest and a Castle
class Knight {
String title = 'Sir'
String name
Quest quest
Castle castle
String toString() { "$title $name" }
static constraints = {
title inList: ['Sir','King','Lord','Squire']
name blank: false
quest nullable: true
castle nullable: true
}
}
The last domain class is Castle , which has a name, a city, a state, and a computed latit-
ude/longitude pair, as shown in the following listing.
Listing 10.15. The Castle , which stores location information
class Castle {
String name
String city
String state
double latitude
double longitude
String toString() { "$name Castle" }
static hasMany = [knights:Knight]
static constraints = {
name blank: false
city blank: false
state blank: false
latitude min: -90d, max: 90d
Search WWH ::




Custom Search