Reputation: 824
I'm having an issue dealing with two entities which should have a relationship of one to many and many to many. Let me show you the case: there are users, which create and take part of activities. So an activity could have several users and just one activity creator, meanwhile an user can create and belong to many activities.
So I did something like this:
class User {
static hasMany = [activities:Activity, activitiesCreated: Activity]
static mappedBy = [activitiesCreated: "creator"]
...
}
class Activity{
static hasMany = [users:User]
static belongsTo = [users:User]
Usuario creator
...
}
This raises a runtime exception, which is this one: No owner defined between domain classes [class User] and [class Activity] in a many-to-many relationship. Example: static belongsTo = Activity
The many-to-many relationship works fine if I don't try to implement the one-to-many, so it wouldn't be the problem.
And this is where I'm stuck :/
Upvotes: 2
Views: 1065
Reputation: 1672
I would have third entity to realize the many to many relationship. For example, let say represent actual execution of the Activities as an Event, which means a Event has one ore more Activities, time stamp/time frame, and one ore more participating Users. A user can create one ore more activity and by the same token the owners of Activity will be considered to own the Event.
Upvotes: 4