Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dev 1022 elementcollection w ids #12140

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Oct 17, 2022

Description

Adds a new craft\elements\ElementCollection class, which extends Illuminate\Support\Collection specifically for collecting element instances, and adds two new methods:

  • ids() – returns a new collection of the IDs of each of the collected elements. (#12113)
  • with() - eager-loads additional elements onto the collected elements and then returns the same ElementCollection object.

craft\elements\db\ElementQuery::collect() and craft\base\Element::getEagerLoadedElements() have both been updated to return new ElementCollection instances rather than Collection, so the following are now possible:

{% set ids = craft.entries()
  .collect()
  .ids() %}
{% set entries = craft.entries()
  .collect()
  .with(['eagerLoadingHandle']) %}

{% for entry in entries %}
  {% set eagerLoadedIds = entry.eagerLoadingHandle.ids() %}
{% endfor %}

Related issues

@brandonkelly brandonkelly requested review from benjamindavid and a team as code owners October 17, 2022 22:32
@linear
Copy link

linear bot commented Oct 17, 2022

@brandonkelly brandonkelly changed the base branch from develop to 4.3 October 17, 2022 22:32
@brandonkelly brandonkelly merged commit 73903fe into 4.3 Oct 17, 2022
@brandonkelly brandonkelly deleted the feature/dev-1022-elementcollection-w-ids branch October 17, 2022 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant