grails-data-mapping
grails-data-mapping copied to clipboard
Unit testing criteria won't bring any results if querying for embedded properties via closure
I added the test case in the EmbeddedAssociationSpec itself inside grails-datastore-gorm-test project.
Task List
- [x] Steps to reproduce provided
- [x] ~~Stacktrace (if present) provided~~
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
Steps to Reproduce
- Declare an entity having an embedded entity;
- Write a method that returns a list provided by a criteria that filters the results by a property from the embedded entity;
- Unit test the above criteria by saving some entities and calling the method that has just been written. Of course insert some entities that match the criteria.
Expected Behaviour
The results should be retrieved.
Actual Behaviour
The list will incorrectly be empty.
Environment Information
- Operating System: macOS Mohave
- Grails Version: 3.3.8
- GORM Version: provided by grails 3.3.8, also master at 47ef76cc11a16e994c198e92e8be66a7d0df84e2
- JDK Version: 1.8
Example Application
- https://github.com/douglasom/grails-data-mapping/commit/8af6aa59dd9acde792dc5fcad666d0b65bf6a450
I would gladly add the fix too (not only the test case) if I'm pointed to the right direction!
I finally bumped into EmbeddedPropertyQuerySpec and after analysing it I figured the problem is I used the closure notation for the embedded property in the criteria:
embeddedEntity { eq 'prop', 'value' }
It works if written like this:
eq 'embeddedEntity.prop, 'value'
I still consider this a bug since I'm used to use the closure notation for embedded entities (not for in memory criteria testing though).