Hi All,
I have created self reference many to many relationship using grails, here's my domain:
Code:
class User {
String username
String password
String fullname
static hasMany=[friends:User]
static mappedBy = [ friends: 'friends' ]
}
which generate two MySQL tables:
Table user:
id bigint primary key
version bigint
username varchar(255)
password varchar(255)
fullname varchar(255)
Table user_friends:
user_id bigint
friends__id bigint
I have done MySQL query successfully to get friends data of a user where its friends of user friends that not current user and current user friends.
Code:
select fullname from user where id in (select friends__id from user_friends where user_id in(select friends__id from user_friends where user_id=16)) and id<>16 and id not in (select friends__id from user_friends where user_id=16)
user_id=16 is current user
My question is how I do it with HQL?