Details
-
Type:
Sub-task
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.0.3
-
Fix Version/s: 1.1-beta3
-
Component/s: Persistence
-
Labels:None
Description
as mentioned here:
http://www.nabble.com/many-to-many-relationship-between-a-tree-and-itself--td18197066.html#a18197066
For example:
class Organization {
//static def belongsTo = [Organization]
static hasMany = [children: Organization, relatedOrganizations: Organization]
//static mappedBy = [children: "parent", relatedOrganizations:"relatedOrganizations"]
Organization parent
String name
}
Without the parent/children tree relation, the many-to-many with self creates a separate organization_organization table as expected for relatedOrganizations. But with it, it doesn't. Instead it duplicates the one-to-many; relatedOrganizations = children.
I tried adding
static mappedBy = [children: "parent", relatedOrganizations:"relatedOrganizations"]
But that generates another unresolvable (circular) problem.
An error is thrown saying:
No owner defined between domain classes [Organization] and [Organization] in a many-to-many relationship.
If I add belongsTo = [Organization], I get this error:
Domain classes [Organization] and [Organization] cannot own each other in a many-to-many relationship. Both contain belongsTo definitions that reference each other.
here's an example of demonstrating the problem of trying to have both a one-to-many and many-to-many with self.
It's like the class above, Organization, with some test data loaded in the bootstrap.
Although you'll have to comment out the mappedBy (and belongsTo) to get that far.