Skip to content

Wrong result for .isAssociation() call when you have a mappedBy closure #14572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mvinas1977 opened this issue May 3, 2018 · 3 comments
Open

Comments

@mvinas1977
Copy link

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

this happens in grails 2.5.6 I didn't test it in grails 3.3.x yet

@mvinas1977
Copy link
Author

In grails 3.3.5 it works fine, so this only affects to grails 2.5.x

@amadfida
Copy link

amadfida commented May 4, 2018

@mvinas1977 can you add also provide GORM and NEO4J-GROM versions.

@amadfida
Copy link

amadfida commented May 4, 2018

@mvinas1977 please open it in GORM and list the env as well ... https://github.com/grails/grails-data-mapping

@jameskleeh jameskleeh transferred this issue from apache/grails-core Nov 1, 2018
@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants