Grails many-to-many and one-to-one with belongsTo -


i'm trying achieve following grails / gorm:

some users lecturers. several users can assistants several lecturers , several lecturers can have several assistants.

i'm trying add additional many-to-many relation existing one-to-one relation between user , lecturer keep belongsto.

this had before:

class user {    ...        lecturer lecturer }  class lecturer {    ...    static belongsto = [user:user] } 

then added many-to-many relationship:

class user {    ...    lecturer lecturer    static hasmany = [lecturers: lecturer] }  class lecturer {        static belongsto = [user:user, assistants:user]    static hasmany = [assistants: user]     } 

i 3 tables:

user:

------------------------------ | id | .. | lecturer_id | .. | ------------------------------ 

lecturer:

----------- | id | .. | ----------- 

user_lecturer:

----------------------------------- | user_lecturers_id | lecturer_id | ----------------------------------- 

when call lecturer.assistants on lecturer without assistant, 1 user. not correct, because table empty. so, guess relation interpreted one-to-many , giving me user lecturer_id matches.

what trick? (mappedby ?)

thanks in advance.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -