You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a domain class property begins with an underscore "_", then there are two propblems:
It cannot be used in a constructor e.g. Book myBook = new Book(_title: "my book") leaves the "_title" property unassigned.
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.
The text was updated successfully, but these errors were encountered:
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".
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.
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:
It cannot be used in a constructor e.g. Book myBook = new Book(_title: "my book") leaves the "_title" property unassigned.
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.
The text was updated successfully, but these errors were encountered: