[Feature Request] Eager-loaded collections should use the same API as non-eager-loaded ones #8513
-
It would be nice if we didn't have to write different code for listing/accessing elements that were eager-loaded vs those that were loaded normally. Kinda similar to what this plugin is doing, but I really believe this should be part of the core. It would be very useful for re-using code (such as Twig macros, or plugin services/variables) that should work with an element query or a collection of elements regardless of whether eager-loading was used or not. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Seems the eager loaded elements could be set on the appropriate |
Beta Was this translation helpful? Give feedback.
-
Yeah that’s probably the direction we’d take for relation fields. But this would be a breaking change so not something we can do until 4.0. |
Beta Was this translation helpful? Give feedback.
-
Just resolved this for Craft 4. Now eager-loaded elements are returned as a Collection, and element queries have a new See #9755 for more details. |
Beta Was this translation helpful? Give feedback.
Just resolved this for Craft 4. Now eager-loaded elements are returned as a Collection, and element queries have a new
collect()
method, which returns the query results as a Collection rather than an array. So if you want a consistent API, just get in the habit of callingcollect()
instead ofall()
.See #9755 for more details.