groovy - Saving associated domain classes in Grails -


I'm struggling to get rights on Grails. Suppose I have two domain squares:

  class engine {string name int number of cylinder = 4 static barriers = {name (empty: incorrect, faucet: wrong) Number of cylinders (category: 4 ..8)}} class car {int-year string brand engine engine = new engine (name: "default engine") static barriers = {engine (faucet: wrong) brand (empty: incorrect, faucet: incorrect) year ( Totally qualified: wrong)}}  

The idea is that the user without first creating an engine Make cars, and those cars get a default engine. I have in the car controller:

  def save = {def car = new car (params) if (! Car.hasErrors ()) & amp; When trying to save the flash.message, I get: "Car saved" redirect (verb: index)} other {render (see: 'create', model: [car: car] )}}  

A tap value exception on the Car.engine field, so the default engine is clearly created and not saved. I manually tried to make the engine:

  def save = {def car = new car (parameter) car.engine = new engine (name: "default engine") if (! .hasErrors (): & quot; car.save ()} {Flash.message = "car saved" redirect (action: index)} and {render (view: 'create', model: [car: car])} }  

Grails is not able to save affiliate classes either? How can I implement such a facility?

I think you need one in your engine i.e.

 < Code> stable relative = [car: car]  

Hope it helps.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -