grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

gorm data service findAllBy dynamic finder method referencing id property does not compile

Open zyro23 opened this issue 7 years ago • 2 comments

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. create a gorm data service like this:
@Service(Dummy)
interface DummyDataService {

    List<Dummy> findAllByIdInList(List<Long> ids)

}
  1. 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

zyro23 avatar Sep 20 '18 14:09 zyro23

This issue still exists on grails latest 5.x version.

xqliu avatar Oct 23 '22 08:10 xqliu

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
    }
}

tonyerskine avatar Nov 14 '22 17:11 tonyerskine