|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Strange behavior on bidirectional one-to-one relationsHi all,
maybe I'm doing something stupid, but I've the following problem. Given the following sample domain classes: class Folder { FolderSpec specification String name static constraints = { name(nullable: false) } } class FolderSpec { static belongsTo = [folder: Folder] String details static constraints = { details(nullable: false) } } 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. The only way to obtain the correct behavior in the first example is adding a setter method on Folder: void setSpecification( FolderSpec spec ) { this.specification = spec if (spec) { this.specification.folder = this } } Is this an expected behavior? I've verified this on grails 1.0.1 and on SVN 6743. Thanks in advance stefano |
|
|
Re: Strange behavior on bidirectional one-to-one relationsI 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 |
|
|
Re: Strange behavior on bidirectional one-to-one relationsHi 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
|
|
|
Re: Strange behavior on bidirectional one-to-one relationsRaise an issue and attach an example app, this doesn't seem correct
Cheers On Fri, Mar 14, 2008 at 10:11 AM, stefano gualdi <stefano.gualdi@...> wrote: > > 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 > > > > -- > View this message in context: http://www.nabble.com/Strange-behavior-on-bidirectional-one-to-one-relations-tp16011577p16047721.html > > > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- Graeme Rocher Grails Project Lead G2One, Inc. Chief Technology Officer http://www.g2one.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Strange behavior on bidirectional one-to-one relationsDone!
GRAILS-2636 Thank you so much Graeme. ciao stefano
|
| Free embeddable forum powered by Nabble | Forum Help |