|
|
|
[
Permlink
| « Hide
]
James Cook - 16/Apr/08 04:34 PM
Attached is a project that has the above classes, the test fails on the last line.
Grails is getting confused by the two relationships from Child to Parent, one is Child.parent and the other is Child.page (created implicitly by the belongsTo field).
It has tried to link the properties via a one-to-one mapping but is doing it incorrectly (Parent.child2 ends up not mapped as a relationship at all, yet Parent.child1 is) which is what is causing both fields on Parent to be set. Was it intentional to have two relationships back to Parent from child? Your test will pass if you comment out either of the lines in Child. cheers Lee Minor mistake in the code. There should not be two references back from Child. It should read:
static belongsTo = [parent:Parent] But it makes no difference - the test still fails. I could live without the declaration of Parent directly in Child, but commenting that line out made no difference to the test failing (given the above modification) Hi James,
apologies, you're right, that doesn't fix the test. I think the best way to avoid problems is to remove the relationship back to Parent and make it a unidirectional one-to-one. Otherwise it becomes impossible for Grails to properly determine the property on Child that is the other side of Parent.child1 and Parent.child2 The other thing I tried which worked was to have two belongsTo links back to Parent e.g. class Parent { static belongsTo = [parent1:Parent, parent2: Parent] } However, I haven't checked to see if there are any other problems with this solution, or how Grails is linking the properties. I'm not sure if there is a bug here or not, if you have two Child properties on Parent and one Parent property on Child how would you expect them to be linked? cheers Lee This might be relevant: http://jira.codehaus.org/browse/GRAILS-3326
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||