gsp - Grails: How to define a domain property rendered on views but not persisted? -
i have domain classes, let's say:
class person { string name integer age //car data needs shown , filled in views //but not persisted in person class string model string color static afterinsert = { def car = new car(model: model, color: color) car.save() } } class car { string model string color }
what need show in person
views (create
, edit
) model , color properties defined inside person
class these doesn't have persisted class. these data, model
, color
, have persisted using car
domain class maybe using afterinsert
event. in other words, need save data domain class using views domain class.
thanks in advance.
you can use transients on properties want gorm ignore, example
class person { static transients = ['model', 'color'] string name integer age //car data needs shown , filled in views //but not persisted in person class string model string color .. }
just curious there reason you're not using associations
class person { .. static hasmany = [cars: car] } class car { .. static belongsto = [person] static hasmany = [drivers: person] }
.. or composition
class person { car car }
or data binding multiple domains
//params passed controller /personcarcontroller/save?person.name=john&age=30&car.model=honda&car.color=red //in controller def person = new person(params.person) def car = new car(params.car)
Comments
Post a Comment