WaZ
WaZ

Reputation: 1757

Binding multiple objects in Grails

I have there domain classes:

In the update method the person controller when I assign a person a designation from a list of designation values I want to insert a new record inside SalarySlip.

Something like:

def update = {
   def SalarySlipInstance = new SalarySlip()
   SalarySlipInstance.Person.ID = Params.ID //is this correct?
   SalarySlipInstance.Designation.ID = ?? //since the value is coming from a list. How can I bind this field?
}

Upvotes: 0

Views: 589

Answers (1)

Dave Bower
Dave Bower

Reputation: 3557

You need to load the Person and Designation objects first:

salarySlipInstance.Person = Person.get(params.person.id)
salarySlipInstance.Designation = Designation.get(params.designation.id)

If in your form you prefix the person and designation id's with person. and designation. it makes it easier to load.

Upvotes: 2

Related Questions