Reputation: 7592
I have got a domain class Track
class Track{
static belongsTo = [createdBy: User, modifiedBy: User, Course]
}
But its giving me error, Finally i dont want to have course object[course: Course] but only have to specify that it belongs to Course [Course]. How to do this
Upvotes: 2
Views: 91
Reputation: 31280
I think you are using the GORM associations a bit too extensively. belongsTo
indicates ownership, and the GORM associations, in general, indicate more about the cascading relationship between objects than anything else.
If you only want to associate User
with your Track
, you just need to have the createdBy
and modifiedBy
fields, which don't need to be in any special sort of association. Then you would have static belongsTo = [Course]
to show that the Course
owns the Track
, meaning that if you deleted the Course
, that the Track
would get deleted as well.
Here's the class I think you are looking for:
class Track {
User createdBy
User modifiedBy
static belongsTo = [Course]
}
Upvotes: 3