gsartori opened a new pull request, #16023:
URL: https://github.com/apache/grails-core/pull/16023

   ## Description
   
   Fixes [#15736](https://github.com/apache/grails-core/issues/15736).
   
   GORM previously generated `hasMany` join-table foreign-key columns from raw 
domain class names using `propertyToColumnName()`. This bypassed 
`classToTableName()`, causing inconsistent names when a custom Hibernate 
`NamingStrategy` transformed entity table names.
   
   This change derives join-table foreign-key prefixes from the resolved entity 
table name. For example:
   
   - `MyappBook` mapped to `book` now produces `book_id`.
   - `Book` mapped to `myapp_book` now produces `myapp_book_id`.
   
   The same behavior is applied consistently to many-to-many and unidirectional 
one-to-many associations.
   
   Regression tests cover both directions:
   
   - Removing `Myapp` from domain class names.
   - Adding `myapp_` to database table names.
   
   The custom naming strategy documentation now explains its effect on 
join-table foreign keys and notes that existing applications may require a 
schema migration.
   
   ## Contributor Checklist
   
   ### Issue and Scope
   
   - [ ] This PR is linked to an existing issue that has been **acknowledged or 
approved** by the project team. If no approved issue exists, please give 
background on why this change is necessary. Tickets are preferred for release 
change log history.
   - [x] This PR addresses the **complete scope** of the linked issue.
   - [x] This PR contains a **single, focused change**.
   - [ ] This PR targets the **correct branch** for the type of change.
   
   ### Code Quality
   
   - [x] I have **added or updated tests** that cover the changes introduced in 
this PR.
   - [ ] I have verified that all existing tests pass by running `./gradlew 
build --rerun-tasks`.
   - [x] My code follows the project's **code style** guidelines. I ran 
`./gradlew :grails-data-hibernate5-core:codeStyle` and resolved all violations.
   - [x] This PR does **not** include mass reformatting, style-only changes, or 
large-scale refactoring.
   - [x] Generative AI tooling was used with a quality model, and the resulting 
changes were reviewed and tested for consistency with the project’s standards.
   
   Targeted verification:
   
   ```text
   ./gradlew :grails-data-hibernate5-core:test \
     --tests 
"grails.gorm.tests.hasmany.jointablenaming.JoinTableNamingStrategySpec"
   ```
   
   Result: 2 tests passed.
   
   ### Licensing and Attribution
   
   - [x] All contributed code is provided under the Apache License 2.0, and the 
new test source includes the appropriate Apache license header.
   - [ ] I have the necessary rights to submit this contribution and confirm it 
is my own original work.
   - [ ] I have followed the Apache Software Foundation's policy on generative 
tooling and properly attributed its use.
   
   ### Documentation
   
   - [x] Relevant documentation was updated to describe how 
`classToTableName()` affects join-table foreign-key columns.
   - [x] This PR does not add a new feature, so no **What's New** update is 
required.
   - [ ] The change can affect generated schema names; the documentation 
includes a migration warning, but the corresponding **Upgrade Notes** have not 
been updated.
   - [x] The PR description clearly explains **what** was changed and **why**.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to