Grails GORM Derived Properties using formulae in subclasses don't work when superclass Domain has tablePerHierarchy false
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
Derived Properties should be working as advertised using `formula` specifications in the `static mapping` block of any Domain class regardless of whether it is a subclass of another Domain class or whether its superclass has set `tablePerHierarchy` to be false in its `static mapping` block.
### Actual Behaviour
Derived Properties are not working using `formula` specifications in the `static mapping` block of a Domain class that is a subclass of another Domain class which has set `tablePerHierarchy` to be false in its `static mapping` block. This means two things:
- Table Creation of the child Domain class will include the column otherwise meant to not exist because of the existence of its `forumla` in the `static mapping` block
- Evaluation of this property at runtime looks to the database stored value instead of evaluating the formula specified
### Steps To Reproduce
See attached project [gorm-formula-bug.tar.gz](https://github.com/grails/grails-core/files/11746413/gorm-formula-bug.tar.gz)
1. Install MySQL or MariaDB
2. Create the Database table schema: `sudo mysql -u root < src/main/sql/create-database.sql`
3. Update Configuration again to change `dbCreate` from `update` to `create-drop`
4. Run the app to seed the schema tables
5. The `bad_parent` table should have a column called bmi while the `good_parent` one does not.
6. Update Configuration again to change `dbCreate` from `create-drop` to `update`
7. Run the app to observe log output
- Child 1 should have null bmi and
- Child 2 should have a non-null bmi
### Environment Information
- Operating System: Cygwin / AlmaLinux 9.2
- MariaDB 10.3.14
- JDK 1.8
### Example Application
_No response_
### Version
5.2.5
Contributor guide
Research direction
Start with the attached gorm-formula-bug.tar.gz project and src/main/sql/create-database.sql, then inspect the Domain classes' static mapping blocks and dbCreate configuration. Reproduce the schema and runtime steps with MariaDB. Done means the bad_parent table omits the formula column and both child properties evaluate the configured formula rather than a stored value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, mariadb
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100