Skip to content

Commit

Permalink
Merge branch 'release/1.0.6' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 20, 2019
2 parents 1953cfa + 071b667 commit e9b9be0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/services/Similar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Similar extends Component
public $limit;

public $targetElements;

// Public Methods
// =========================================================================

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -139,8 +140,8 @@ 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') {
$query->subQuery->addGroupBy('structureelements.lft');
if ($query->elementType === 'craft\elements\Entry') {
$query->subQuery->addGroupBy(['structureelements.structureId', 'structureelements.lft']);
}
$event->isValid = true;
}
Expand Down

0 comments on commit e9b9be0

Please sign in to comment.