Reputation: 606
I have two domain class as shown below. The top level class Client contains three references to Address class. It is a kind of 1..3 relationship. I want the Address objects to be saved by cascading when I save Client. What is the correct way to map such a relationship?
class Client {
Address primaryAddress
Address billingAddress
Address shippingAddress
static hasOne = [primaryAddress: Address, billingAddress: Address, shippingAddress: Address]
}
class Address {
String addressLine1
String addressLine2
String addressLine3
}
Upvotes: 1
Views: 85
Reputation: 34011
hasOne
maps the reference FROM the child to the parent (docs). So in your case, that would means each Address
would store a reference to a Client
, rather than an Address
storing three references to Clients
. From the sound of your question, that is not what you want, so you can just remove the whole hasOne
mapping and stick with simple references.
Upvotes: 1