Tags: cakephp/orm
Tags
Fix paginated association subqueries on MariaDB (#19596) Use DISTINCT for ungrouped association filter queries so MariaDB does not apply its lateral GROUP BY optimization. Preserve explicit grouping and select ordered columns for PostgreSQL compatibility. * Test paginated MariaDB association results Refs #19595. --------- Co-authored-by: Mark Scherer <dereuromark@users.noreply.github.com>
Fix two subquery eager loading strategy defects A nested matching builder was inherited by every association leading up to its target. EagerLoader::setMatching() spreads the shared options over each segment of the association path, and the options carry the target's queryBuilder when the nested matching is rebound from a surrogate query. The parent association then applied the target's conditions to its own join, which produced an ON clause referencing a table that is only joined later. The first build of a query happened to escape it, so it surfaced when the query was cloned, for instance while building a subquery strategy filter. The subquery filter also groups by the source binding key and keeps the query's LIMIT, so the limit cuts the distinct keys instead of the rows the query returned. Both sets only coincide while the association is owned by the query's own repository. Where the association hangs off another association, many rows share one key, the filter answers with a different set of keys, and the association silently comes back empty. Those loaders now use the select strategy, which filters on the keys of the rows that were actually returned.
Keep the ORDER BY intact when building a subquery strategy filter (#1… …9538) _subqueryFields() collects the ORDER BY fields through iterateParts(), which rebuilds the expression from whatever the callback returns. The callback returned nothing, so every part was dropped - and since it runs against the caller's query rather than a clone, the query itself was left without an ORDER BY. The loader of the first contained association therefore stripped the order, and every following association built its filtering subquery unordered. With a limit in place those subqueries paged onto the wrong rows, so any hasMany after the first one silently returned no results at all. * Add closure param type for rector * Fix CS --------- Co-authored-by: Mark Scherer <dereuromark@gmail.com>
Fix ambiguous column in self-referential subquery eager loading (#19397) * Fix ambiguous column in self-referential subquery eager loading When a HasMany association is self-referential (e.g. a tree structure with parent_id), the subquery eager loading strategy joins the subquery using the source alias which is the same as the outer query table alias. This causes 'Column X.id in SELECT is ambiguous' errors. Use a suffixed alias for the subquery join when source and target aliases match, and update the filter identifiers accordingly. * Fix subquery eager loading edge cases * Add eager loading regression coverage * Fix CI issues in eager loading regressions * Skip non-portable SQLServer regression cases
PreviousNext