From 3c06b751e246c7e5ae5ce10942684b076cdb7eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Svale=20Fossa=CC=8Askaret?= Date: Thu, 11 Apr 2019 11:30:47 +0200 Subject: [PATCH 1/3] Add structureelements.structureId to groupBy Fixes sql error (contains nonaggregated column) --- src/services/Similar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/Similar.php b/src/services/Similar.php index 00a21c7..805bbc0 100644 --- a/src/services/Similar.php +++ b/src/services/Similar.php @@ -140,7 +140,7 @@ protected function eventAfterPrepareHandler(CancelableEvent $event) $query->subQuery->groupBy('elements.id'); if($query->elementType == 'craft\elements\Entry') { - $query->subQuery->addGroupBy('structureelements.lft'); + $query->subQuery->addGroupBy(['structureelements.structureId', 'structureelements.lft']); } $event->isValid = true; } From 197e4944b84f432343e28a6e71cc30ad4771870e Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 20 Apr 2019 16:17:43 -0400 Subject: [PATCH 2/3] Code cleanup Signed-off-by: Andrew Welch --- src/services/Similar.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/Similar.php b/src/services/Similar.php index 805bbc0..52ac938 100644 --- a/src/services/Similar.php +++ b/src/services/Similar.php @@ -41,6 +41,7 @@ class Similar extends Component public $limit; public $targetElements; + // Public Methods // ========================================================================= @@ -105,7 +106,7 @@ public function find($data) $elements = Craft::$app->getElements(); $models = []; foreach ($results as $config) { - if($config['id'] && $config['siteId']) { + if ($config['id'] && $config['siteId']) { $model = $elements->getElementById($config['id'], $elementClass, $config['siteId']); if ($model) { // The `count` property is added dynamically by our CountBehavior behavior @@ -139,7 +140,7 @@ protected function eventAfterPrepareHandler(CancelableEvent $event) $query->query->limit($this->limit); // or whatever limit is set $query->subQuery->groupBy('elements.id'); - if($query->elementType == 'craft\elements\Entry') { + if ($query->elementType === 'craft\elements\Entry') { $query->subQuery->addGroupBy(['structureelements.structureId', 'structureelements.lft']); } $event->isValid = true; From 071b66738edc94292a88beea012bdf07f76c5956 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 20 Apr 2019 16:18:04 -0400 Subject: [PATCH 3/3] Version 1.0.6 Signed-off-by: Andrew Welch --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f2da0c..a1119ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Similar Changelog +## 1.0.6 - 2019-04-20 +### Changed +* Add `structureelements.structureId` to `GROUP BY` clause + ## 1.0.5 - 2019-01-05 ### Changed * Fix SQL error: Unknown column `structureelements.lft` in 'group statement for Products diff --git a/composer.json b/composer.json index 9ea9204..d118567 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-similar", "description": "Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.", "type": "craft-plugin", - "version": "1.0.5", + "version": "1.0.6", "keywords": [ "craft", "cms",