From 37994d380266a214a6f46714ad836bd0dea66378 Mon Sep 17 00:00:00 2001 From: Aaron Waldon Date: Wed, 13 Sep 2017 12:07:52 -0400 Subject: [PATCH] Eager loading fix Added an element query modification to allow eager loading to work with Focus Point. --- .../FocusPoint_AssetElementType.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/focuspoint/elementtypes/FocusPoint_AssetElementType.php b/focuspoint/elementtypes/FocusPoint_AssetElementType.php index 1f7d36f..6761dee 100644 --- a/focuspoint/elementtypes/FocusPoint_AssetElementType.php +++ b/focuspoint/elementtypes/FocusPoint_AssetElementType.php @@ -13,4 +13,20 @@ public function populateElementModel($row) $model = FocusPoint_AssetFileModel::populateModel($row); return $model; } -} \ No newline at end of file + + /** + * Adds the focusX and focusY points to the row that populates the model. This + * allows the focus point to still work with eager loading. + * + * @param DbCommand $query + * @param ElementCriteriaModel $criteria + */ + public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) + { + $query + ->addSelect('ff.focusX, ff.focusY') + ->leftJoin('focuspoint_focuspoints ff', 'ff.assetId = elements.id'); + + parent::modifyElementsQuery($query, $criteria); + } +}