apache / apache/grails-core

Unit testing criteria won't bring any results if querying for embedded properties via closure

Open
#14,537 2 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

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

1. Declare an entity having an embedded entity;
2. Write a method that returns a list provided by a criteria that filters the results by a property from the embedded entity;
3. 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

Contributor guide

Open the contributing guide

Research direction

Start with the added test case in EmbeddedAssociationSpec in the grails-datastore-gorm-test project and review the reproducing example at commit 8af6aa59dd9acde792dc5fcad666d0b65bf6a450. Run the test for a criteria query filtering on an embedded property, then trace why matching saved entities are not returned. Done means the criteria returns the expected matching results.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.