« Return to Thread: Strange behavior on bidirectional one-to-one relations

Re: Strange behavior on bidirectional one-to-one relations

by stefano gualdi :: Rate this Message:

Reply to Author | View in Thread

Hi Robert,

thanks for your answer.

Yes, but what if you need to set the field in a second time?

Imagine to have this case:

def folder = new Folder(name:'MainFolder', startSpecification: spec1, endSpecification: null)

endSpecification will be set after some time because is not available at the moment.

Later you can do:

def spec = new FolderSpec(details:'dummy1')
def folder = Folder.get(someid)
folder.endSpecification = spec
folder.save(flush:true)

that, without the explicit setter, will non work (at least in my case).

Please can you send me a reference for the documentation you are talking about?

I'm sure I'm missing something but I can't figure out what!!!!

Thanks

stefano

Robert B wrote:
stefano gualdi wrote:
If i create a new Folder object with this code:

def spec = new FolderSpec(details:'dummy')
def folder = new Folder(name:'MainFolder')
folder.specification = spec
folder.save(flush:true)

the reference 'folder' on FolderSpec remains null. While, using this:

def spec = new FolderSpec(details:'dummy')
def folder = new Folder(name:'MainFolder', specification: spec)
folder.save(flush:true)

everything works as expected.
I thought that according to the documentation, you're supposed to create the objects as follows, to get the cascading behavior:

def folder = new Folder(specification:new FolderSpec(details:'dummy'))
folder.save(flush:true)

--Rob

 « Return to Thread: Strange behavior on bidirectional one-to-one relations