Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Conversation

@wesrice
Copy link
Contributor

@wesrice wesrice commented Feb 4, 2016

I added a check to see if the behavior is already attached to the element. This allows you to use the fetch service multiple times on the same source elements.

Consider the following scenario.

$elements = craft()->fetch->elements('Asset', $elements, ['images']);
$elements = craft()->fetch->elements('Category', $elements, ['categories']);

Craft::dd($elements[0]->fetch('images'));

In the code above, related Asset elements are fetched and attached to the source elements. Then the source elements with the attached fetched_elements are passed to the fetch service to retrieve related categories. However, a new fetched_elements behavior will be attached again, losing the previously fetched images. This results in $elements[0]->fetch('images') returning null instead of the expected AssetFileModels collection.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant