grails-data-mapping
grails-data-mapping copied to clipboard
gorm data service findAllBy dynamic finder method referencing id property does not compile
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
- create a gorm data service like this:
@Service(Dummy)
interface DummyDataService {
List<Dummy> findAllByIdInList(List<Long> ids)
}
- try to compile (e.g.
gradle(w) classes)
Expected Behaviour
data service should compile
Actual Behaviour
Cannot implement finder for non-existent property [id] of class [myapp.Dummy]
@ line 9, column 2.
List<Dummy> findAllByIdInList(List<Long> ids)
^
1 error
:compileGroovy FAILED
Environment Information
- Operating System: win x64
- GORM Version: 6.1.10
- Grails Version (if using Grails): 3.3.8
- JDK Version: oracle 8u151
Example Application
- sample app will be referenced in a minute
This issue still exists on grails latest 5.x version.
I had to work around this with an abstract class. I would love a cleaner solution:
import grails.gorm.services.Service
@Service(CardholderGroup)
abstract class CardholderGroupDataService {
abstract CardholderGroup get(Serializable id)
CardholderGroup findByIdAndOrganization(Long id, Organization organization) {
CardholderGroup cardholderGroup = get(id)
return cardholderGroup.organization == organization ? cardholderGroup : null
}
}