gorm - Multiple many-to-many associations in one Grails domain class -


i using grails 3.0.6 , struggling complicated , highly interconnected domain model. have classes multiple many-to-many associations other classes , left no choice have multiple belongsto associations on @ least 1 class. unable figure out syntax represent this.

my domain model quite complicated, able reduce problem simplified example:

class graph {     static hasmany = [vertices: vertex] }  class otherclass {     static hasmany = [vertices: vertex] }  class vertex {     static hasmany = [graph: graph, other: otherclass] } 

in simplified example, around problem declaring ownership between domain classes on graph , otherclass... in complicated domain model, don't have choice because there many classes multiple many-to-many associations.

i have tried this:

class vertex {     static hasmany = [graphs: graph, others: otherclass]     static belongsto = graph, otherclass } 

but npe.

i have tried this:

class vertex {     static hasmany = [graphs: graph, others: otherclass]     static belongsto = [graphs: graph, others: otherclass] } 

but still "grailsdomainexception: no owner defined between domain classes [graph] , [vertex]"

is there mappedby correctly represent this?

in many of many-to-many associations, cascading saves not wanted (although won't hurt), don't need belongsto (or "owner") purpose. makes me wonder if associations on domain classes how should modeling these relationships. there else doing?

per burt beckwith's comment, created additional domain class represent join table. now, 1 many-to-many association broken down 2 one-to-many associations , problem not arise.

example:

class graph {     static hasmany = [graphvertexrelations: graphvertexrelation] }  class otherclass {     static hasmany = [vertices: vertex] }  class vertex {     static hasmany = [graphvertexrelations: graphvertexrelation, others: otherclass]     static belongsto = otherclass }  class graphvertexrelation {     static belongsto = [graph: graph, vertex: vertex]      static graphvertexrelation create(graph graph, vertex vertex, boolean flush = false) {         new graphvertexrelation(graph: graph, vertex: vertex).save(flush: flush, insert: true)     } } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -