Skip to content
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

GRAILS-7761: Domain class properties that begin with an underscore "_" break dynamic finders and constructor assigned properties. #5919

Closed
graemerocher opened this issue Jul 19, 2011 · 2 comments

Comments

@graemerocher
Copy link
Member

Original Reporter: xnickmx
Environment: Windows 7
Version: 1.3.6
Migrated From: http://jira.grails.org/browse/GRAILS-7761

If a domain class property begins with an underscore "_", then there are two propblems:

  1. It cannot be used in a constructor e.g. Book myBook = new Book(_title: "my book") leaves the "_title" property unassigned.

  2. It cannot be used in a dynamic finder e.g. Book myBook = Book.findBy_title("my book") throws an exception:

    org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [by_title] for class [class org.grails.example.domain.Book]

The good news is that there are workarounds for both of these issues.
To work around #1, don't put the property into the constructor and instead assign it on its own line e.g. myBook._title = "my book"
To work around #2, use a HQL query e.g. Book.find("from Book as b where b._title = :title", [title: "my book"])

Bug report attached with integration tests that fail and workarounds demonstrated.

@graemerocher
Copy link
Member Author

burtbeckwith said:
This reminds me of the old joke where a guy goes into a doctor's office and says "Hey doc, it hurts when I do this". The doctor replies "Simple fix - don't do that".

@graemerocher
Copy link
Member Author

xnickmx said:
I figured I'd log it so that if anyone else encountered it there would at least be some documentation. The constructor error was quite maddening and took a little while to figure out because it didn't fail immediately.

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

1 participant