From c926d33562c94c87796e45507d1d07264e52b862 Mon Sep 17 00:00:00 2001 From: Wes Rice Date: Thu, 4 Feb 2016 07:39:04 -0500 Subject: [PATCH] Check to see if behavior is already attached to element --- services/FetchService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/FetchService.php b/services/FetchService.php index ebc894e..71200c1 100644 --- a/services/FetchService.php +++ b/services/FetchService.php @@ -45,7 +45,10 @@ public function elements($elementType, array &$sourceElements, $fieldHandles = n // Attach the behavior to each of the source elements foreach($sourceElementsById as $sourceElement) { - $sourceElement->attachBehavior('fetched_elements', new Fetch_FetchedElementsBehavior()); + // Make sure the behavior hasn't already been attached + if (!$sourceElement->asa('fetched_elements')) { + $sourceElement->attachBehavior('fetched_elements', new Fetch_FetchedElementsBehavior()); + } } // Perform the first query to get the information from the craft_relations table