Files
RenHai Wen ec1db7c43d fix: respect table prefixes in query builder relationship aggregates (#20386)
* fix: respect table prefixes in query builder relationship aggregates

* fix: preserve one-of-many relationship semantics in query builder aggregates

* fix: respect relationship method constraints in query builder aggregates

Aggregate subqueries were built from a fresh query on the related model,
so constraints defined inside the relationship method itself were never
applied. An aggregate over a relationship such as
`hasMany(Post::class)->where('is_published', true)` silently aggregated
every related row, and `wherePivot()` on a `BelongsToMany` was ignored
in the same way.

Merge the relationship's own query into the subquery with
`mergeConstraintsFrom()`, matching how Laravel builds its own
`withAggregate()` subqueries.

---------

Co-authored-by: Dan Harrin <git@danharrin.com>
2026-08-25 11:24:44 +01:00
..