views:

90

answers:

1

Hi,

using Grails 1.1.1

I have domain in Grails Person. Person can be related to another Person buut they can be stand alone. this is like:

I have A as my friend and A have me as his friend

B can be stand alone (not having friend)

should I type

Person {
 belongsTo = [friend:Person]
 hasMany = [persons:Person]

 constraints {
   friend(nullable:true)
 } 

}

and how to delete A ?

+1  A: 

Why do you need the friend property? Don't you just want a person to have zero to many friends?

Person {
 hasMany = [friends:Person]
}
leebutts
can I have like this : Person person1 = new Person();.... details and saving object ... Person person2 = new Person();person1.addFriends(person2);should I addFriend from person2 ?like person2.addFriends(person1) ?
nightingale2k1
yes, you need to add it from both sides of the relationship
leebutts