Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 2.0.3, 2.0.4
-
Component/s: Data binding
-
Labels:None
-
Environment:Ubuntu
-
Testcase included:yes
Description
The binding of foreign key domains fails when the foreign key is defined in the parent class after upgrading from version 2.0.1
For example, with the base class person:
class Person {
Name name
String occupation
static constraints = {
}
static mapping = {
name cascade: "all"
}
}
and the implementing class PersonExtended:
class PersonExtended extends Person { static constraints = { } }
and the foreign key Name:
class Name {
String title
String firstName
String surname
static constraints = {
}
}
I am unable to set the name fields on PersonExtended with the same params that works ok for Person.
def personInstance = new Person(params) def personExtendedInstance = new PersonExtended(params) assert personInstance.name // Passes assert personExtendedInstance.name // Fails
I have attached a sample 2.0.4 project with a single unit test to illustrate the issue.
-
Hide
- bindingissue.zip
- 08/Jun/12 4:02 AM
- 116 kB
- Bill Thornton
-
- bindingissue/.classpath 0.7 kB
- bindingissue/.project 0.5 kB
- bindingissue/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- bindingissue/application.properties 0.1 kB
- bindingissue/.../ApplicationResources.groovy 0.1 kB
- bindingissue/grails-app/.../BootStrap.groovy 0.1 kB
- bindingissue/.../BuildConfig.groovy 2 kB
- bindingissue/grails-app/.../Config.groovy 4 kB
- bindingissue/.../DataSource.groovy 1 kB
- bindingissue/.../UrlMappings.groovy 0.2 kB
- bindingissue/grails-app/.../resources.groovy 0.0 kB
- bindingissue/.../PersonController.groovy 0.7 kB
- bindingissue/grails-app/.../Name.groovy 0.1 kB
- bindingissue/.../NameAbstract.groovy 0.1 kB
- bindingissue/grails-app/.../Person.groovy 0.2 kB
- bindingissue/.../PersonExtended.groovy 0.1 kB
- bindingissue/.../messages.properties 3 kB
- bindingissue/.../messages_cs_CZ.properties 3 kB
- bindingissue/.../messages_da.properties 3 kB
- bindingissue/.../messages_de.properties 4 kB
- bindingissue/.../messages_es.properties 3 kB
- bindingissue/.../messages_fr.properties 2 kB
- bindingissue/.../messages_it.properties 2 kB
- bindingissue/.../messages_ja.properties 4 kB
- bindingissue/.../messages_nl.properties 3 kB
- bindingissue/.../messages_pt_BR.properties 3 kB
- bindingissue/.../messages_pt_PT.properties 3 kB
- bindingissue/.../messages_ru.properties 4 kB
- bindingissue/.../messages_sv.properties 3 kB
- bindingissue/.../messages_th.properties 6 kB
Issue Links
- is related to
-
GRAILS-8998
Custom structured property editor data binding support broken after upgrade from 2.0.1 to 2.0.2 / 2.0.3
-
- relates to
-
GRAILS-9165
Cannot bind Date to subclass domain posting from enctype=multipart/form-date
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Bill,
I think I have fixed the binding problem. However, your test is still failing. The assertions in the controller are passing because the binding works now but there is an assertion in the test that is still failing.
package bindingissue import grails.test.mixin.* @TestFor(PersonController) @Mock([Person, PersonExtended, Name]) class PersonControllerTests { def populateValidParams(params) { assert params != null params['occupation'] = "Computer Programmer" params['name.title'] = "Mr" params['name.firstName'] = "John" params['name.surname'] = "Smith" } void testSave() { populateValidParams(params) controller.save() assert response.json.person assert response.json.person.occupation assert response.json.person.name // For some reason the name fields are not being output via json so this fails assert response.json.person.name.title assert response.json.personExtended assert response.json.personExtended.occupation assert response.json.personExtended.name assert response.json.personExtended.name.title } }
The response.json.person.name.title assertion is failing. That seems like a separate issue. It looks like the assertions that you have in the controller cover the data binding concerns. Is that correct?
Hi Jeff,
Many thanks for looking at the issue.
Yes, the assertions in the controller are the ones that cover this specific issue. I am unsure why the "response.json.person.name.title" assert fails, but it is not to do with the raised issue.
Cheers,
Bill
Bill,
Great.
If you would, please raise a separate JIRA for the JSON issue. So as not to complicate the issue it is probably best to leave the data binding concern out of that one. I think the 2 are almost certainly unrelated issues. In a sample app for that one you could eliminate the data binding issue by just creating the object graph yourself without using data binding and then rendering that object as JSON.
Thanks again for the help.
This isn't really the same problem as GRAILS-8998 but the 2 were fixed at the same time. When testing the fix for GRAILS-8998 I realized the inheritance problem as it relates to structured editors and fixed it. That fix covers the issue described here as well.
Sorry for the trouble.
Same issue experienced please fix