[Craft 4] Add .one() to Collections... or revive .first() for element queries 😬 #11134
-
Having eager-loaded elements returned as Collections in Craft 4 is awesome, as it greatly reduces the need for boilerplate when having to write code that loops over elements that may or may not be eager-loaded. Unfortunately though, fetching a single element in a lazy/eager agnostic way is still a little bit awkward, since there's no {% set image = entry.image.collect().first() %} Which... works, but is arguably not as nice as the familiar To increase API parity between the two interfaces and make it even easier to write code that works for both lazy and eager loaded elements, it'd be great if Craft could provide a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Good idea. Added a |
Beta Was this translation helpful? Give feedback.
Good idea. Added a
one()
alias, for Craft 4.1! (6e56bda)