Wrong result for .isAssociation() call when you have a mappedBy closure
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
I found something that looks like a gorm issue
I have this simple model
```
abstract class BaseDomain {
User createdBy
static constraints = {
createdBy(nullable: false)
}
}
class User extends BaseDomain {
String userName
User supervisor
static constraints = {
}
static mappedBy = [
createdBy: null
]
}
class Data extends BaseDomain {
String otherField
}
```
If you look user it has this mappedBy closure
static mappedBy = [
createdBy: null
]
because I don't want to have createdBy mapped automatically to the user set in supervisor, we really have a listener to set it.
I need to know if the property createdBy is an association or not, so I do:
```
def app = Holders.getGrailsApplication()
GrailsDomainClass dc = app.getArtefact(DomainClassArtefactHandler.TYPE, Data.name)
assert dc.getPersistentProperty(propertyName).isAssociation()
```
It returns false when it should return true, if User has no mappedBy closure, it works fine
I have an application shared with this domain classes and a couple of tests cases to reproduce this error if you like use it
[https://github.com/mvinas1977/gorm-association-issue](https://github.com/mvinas1977/gorm-association-issue)
**this happens in grails 2.5.6 I didn't test it in grails 3.3.x yet**
Contributor guide
Research direction
Start with the domain classes and reproduction application in https://github.com/mvinas1977/gorm-association-issue, then trace GrailsDomainClass.getPersistentProperty(propertyName).isAssociation() for Data.createdBy when User defines mappedBy. Done means the property is reported as an association in the Grails 2.5.6 scenario while preserving the mappedBy behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100