Hi,
I have what is probably a simple question. I'm working with the
Spring Security Core Plugin. My application will create new
application objects in the database to be associated with each user.
The simple question is what is the proper/Grails way of making the
user/domain object relationship?
The two ways that I currently know about is using the "belongsTo"
specifier as in the following:
class Team {
static belongsTo= [ user : User]
...
}
And then in the 'save' method simply assigning
teamInstance.user = springSecurityService.currentUser
The other way would be to do the following:
class Team {
User user
...
}
And then in the 'save' method simply assigning
teamInstance.user = springSecurityService.currentUser
I guess another option would be to do this:
class Team {
Long userID
...
}
And then in the 'save' method simply assigning
teamInstance.userID =
springSecurityService.principal.id
Is there is a preferred way of doing this? It seems like there
aught to be a way to inject the association automatically somehow as
well.
On a related note...Is it illegal to have more than one 'belongsTo'
association? For instance I need the 'belongsTo' for the User but
then need the normal domain associations as well. My many-to-many
associations seem to only allow for one 'belongsTo'.
Thanks,
Brent Hale