Skip to content

Fix generics model pointers for updates and add Join method#7730

Open
MarlinKuhn wants to merge 6 commits intogo-gorm:masterfrom
MarlinKuhn:master
Open

Fix generics model pointers for updates and add Join method#7730
MarlinKuhn wants to merge 6 commits intogo-gorm:masterfrom
MarlinKuhn:master

Conversation

@MarlinKuhn
Copy link

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fixes #7713

User Case Description

If you use generics and want to use the Set to update values on a model with hooks it fails currently.

@propel-code-bot
Copy link
Contributor

propel-code-bot bot commented Mar 12, 2026

Add generic Join support and fix model pointer usage in generics

This PR adds a new Join method to the generics chain API and introduces the ExternalJoinBuilder interface, enabling external joins with ON conditions built from a scoped builder. It also adjusts join table handling when jt.Table is empty or clause.CurrentTable, and refines Count to avoid Select("*") when a column is not specified.

Additionally, several generics update/create paths now pass a pointer model via new(T) to Model(...), fixing update/Set flows that require model hooks to run properly.

Key Changes

• Added Join to ChainInterface[T] with a new ExternalJoinBuilder interface for building external join conditions in generics.go
• Updated Joins and Join to normalize jt.Table when empty or equal to clause.CurrentTable
• Switched generics update/create/association operations to use new(T) for Model(...) in Update, Set updates, Create, and association operations
• Adjusted Count to only call Select when a non-empty, non-* column is provided

Affected Areas

generics.go
ChainInterface[T] API
JoinBuilder and new ExternalJoinBuilder behavior
• Generics update/create/association flows

This summary was automatically generated by @propel-code-bot

@propel-code-bot propel-code-bot bot changed the title Generics: Fix Hooks not working on update/create Fix generics hooks for update/create and add Join Mar 13, 2026
propel-code-bot[bot]

This comment was marked as outdated.

@propel-code-bot propel-code-bot bot changed the title Fix generics hooks for update/create and add Join Fix generics model handling for updates and add Join Mar 13, 2026
Copy link
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Join handling may drop subqueries, requiring adjustment for correctness.

Status: Changes Suggested | Risk: Medium

Issues Identified & Suggestions
  • Handle subquery joins in Join to avoid silent drops: generics.go
Review Details

📁 1 files reviewed | 💬 1 comments

👍 / 👎 individual comments to help improve reviews for you

}
}

join := clause.Join{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

[Logic] Join ignores jt.Subquery. If callers use JoinTarget.AssociationFrom or populate Subquery, this will silently drop the subquery and join on jt.Association as a table name. Is that intentional? If subquery joins should work here, add handling similar to Joins (building join.Expression with a NamedExpr over jt.Subquery).

Context for Agents
`Join` ignores `jt.Subquery`. If callers use `JoinTarget.AssociationFrom` or populate `Subquery`, this will silently drop the subquery and join on `jt.Association` as a table name. Is that intentional? If subquery joins should work here, add handling similar to `Joins` (building `join.Expression` with a `NamedExpr` over `jt.Subquery`).

File: generics.go
Line: 452

Copy link
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review found no issues with the proposed changes.

Status: No Issues Found | Risk: Low

Review Details

📁 1 files reviewed | 💬 0 comments

@propel-code-bot propel-code-bot bot changed the title Fix generics model handling for updates and add Join Fix generics model pointers for updates and add Join method Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generics API: Updates ( ctx, t ) and Hook cannot be used together

1 participant