From a9de8b95afddfa3a1ee72de22fbd954f31140e5d Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 12 Apr 2026 14:15:41 +0200 Subject: [PATCH] improve ORM strategy changes --- docs/en/appendices/5-4-migration-guide.md | 1 + docs/en/orm/associations.md | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/en/appendices/5-4-migration-guide.md b/docs/en/appendices/5-4-migration-guide.md index d350869cf4..df06dbca21 100644 --- a/docs/en/appendices/5-4-migration-guide.md +++ b/docs/en/appendices/5-4-migration-guide.md @@ -44,6 +44,7 @@ version is reported as `unknown`), the header is omitted. - The default eager loading strategy for `HasMany` and `BelongsToMany` associations has changed from `select` to `subquery`. If you need the previous behavior, explicitly set `'strategy' => 'select'` when defining associations. + See [Associations](../orm/associations#has-many-associations) for more details. ### Controller diff --git a/docs/en/orm/associations.md b/docs/en/orm/associations.md index 8d4a36a97b..3b2bd30e5d 100644 --- a/docs/en/orm/associations.md +++ b/docs/en/orm/associations.md @@ -462,9 +462,12 @@ Possible keys for hasMany association arrays include: - **propertyName**: The property name that should be filled with data from the associated table into the source table results. By default, this is the underscored & plural name of the association so `comments` in our example. -- **strategy**: Defines the query strategy to use. Defaults to 'subquery'. The - other valid value is 'select', which uses the `IN` list of parent keys +- **strategy**: Defines the query strategy to use. Defaults to `subquery`. The + other valid value is `select`, which uses the `IN` list of parent keys directly instead of a subquery. +::: tip New default strategy in version 5.4+ +The default strategy has changed from `select` to `subquery` in order to improve performance when the number of parent keys is large. +::: - **saveStrategy**: Either `append` or `replace`. Defaults to `append`. When `append` the current records are appended to any records in the database. When `replace` associated records not in the current set will be removed. If the foreign key is a nullable @@ -616,9 +619,12 @@ Possible keys for belongsToMany association arrays include: - **propertyName**: The property name that should be filled with data from the associated table into the source table results. By default, this is the underscored & plural name of the association, so `tags` in our example. -- **strategy**: Defines the query strategy to use. Defaults to 'subquery'. The - other valid value is 'select', which uses the `IN` list of parent keys +- **strategy**: Defines the query strategy to use. Defaults to `subquery`. The + other valid value is `select`, which uses the `IN` list of parent keys directly instead of a subquery. +::: tip New default strategy in version 5.4+ +The default strategy has changed from `select` to `subquery` in order to improve performance when the number of parent keys is large. +::: - **saveStrategy**: Either `append` or `replace`. Defaults to `replace`. Indicates the mode to be used for saving associated entities. The former will only create new links between both side of the relation and the latter will