Hello,
I'm part of a team of developers and we're working in our second grails project. We're still learning some great features of grails and one question has come to our mind.
We have some domain classes with relationships to others. My question is.. is there a way to hydrate (fill in the attributes of the domain with, for example, the params map) a domain object and its relationships?
For example, if I have these two domain classes:
User{
String name
String NIF
static belongsTo = [profile:Profile]
}
Profile {
String profileName
}
and I have a form like this one:
<g:form name="userForm" action="save">
<g:textField name="name" value="${userInstance?.name}"/>
<g:textField name="NIF" value="${userInstance?.NIF}"/>
<g:textField name="profile.profileName" value="${userInstance?.profile?.profileName}"/>
<g:submitButton name="create" value="Create"/>
</g:form>
could we in the controller just write this to save the user and the profile?
def save = {
def userInstance = new User(params)
user.save()
...
}
Many thanks.


Reply With Quote
