Grails - Data Binding One to One Association Not Working

260 Views Asked by At

I'm trying to do a straight forward data bind that involved two domain classes in a one to one association. Here's the two classes:

class Request
{
  static hasOne = [form: Form]

  Form form
}

class Form
{
  static belongsTo = [request: Request]

  String string
}

I then do the following data binding (this is to demonstrate the problem ... the real data bind comes from a form):

Request request = new Request()
request.properties = ['form.string': 'string value']

However, I end up with a Request object that has a null form property instead of a Request object that has a Form object for its form property along with the string value.

2

There are 2 best solutions below

0
On BEST ANSWER

Turns out the problem wasn't with the actual classes, but the map being passed to the data binding. Even though according to the Grails documentation the following should have worked:

Request request = new Request()
request.properties = ['form.string': 'string value']

it doesn't. However, if I change the map to be I get proper binding:

Request request = new Request()
request.properties = [form: [string: 'string value']]
4
On

Try with this

class Request
{
  Form form
}

class Form
{
  static belongsTo = [request: Request]

  String string
}