Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criteria parameter isn't applied [Craft 4.4.9] #50

Closed
croxton opened this issue May 21, 2023 · 6 comments
Closed

Criteria parameter isn't applied [Craft 4.4.9] #50

croxton opened this issue May 21, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@croxton
Copy link

croxton commented May 21, 2023

Describe the bug

criteria doesn't seem to limit the resultset.

To reproduce

{% set ids = entry.relatedTopics.ids() %}
{% set limitCriteria = craft.entries.section(['awards']).limit(1) %}
{% set similarEntries = craft.similar.find({
   element: entry,
   context: ids,
   criteria: limitCriteria
}) %}

{# result: similarEntries has entries related to `ids` but contains entries in sections other than 'awards', and is not limited to 1 entry #}

Expected behaviour

criteria should be used as the base element query that Similar extends.

Versions

  • Plugin version: 4.0.0
  • Craft version: 4.4.9
@croxton croxton added the bug Something isn't working label May 21, 2023
@croxton
Copy link
Author

croxton commented May 21, 2023

Interesting - this works as expected:

{% set ids = entry.relatedTopics.ids() %}
{% set similarEntries = craft.similar.find({
   element: entry,
   context: ids,
   criteria:  {
      limit : 1,
      section: 'awards'
   }
}) %}

@khalwat
Copy link
Contributor

khalwat commented May 22, 2023

Hrm yeah not sure why that would be, but it sounds like we have a work-around?

I'll close this up, but if you want to look into why it wouldn't work for a query but would for an object, feel free. It'd be interesting to see what's going on.

@khalwat khalwat closed this as completed May 22, 2023
@croxton
Copy link
Author

croxton commented May 22, 2023

Well that's the thing, I think you're doing the right thing here but it just doesn't seem to work anymore. Reasonably sure Similar was working with this pattern in earlier versions of Craft 4:

$criteria = $criteria->toArray();

I'm happy with the workaround, but I guess this could cause issues for people upgrading.

@khalwat khalwat reopened this May 22, 2023
@khalwat
Copy link
Contributor

khalwat commented May 22, 2023

Yeah doesn't make sense to me. It's just converting it into an array. Maybe it contains some other properties that we causing an issue?

In any event, I've re-opened it. Lmk if you find anything more

@khalwat
Copy link
Contributor

khalwat commented Apr 28, 2024

Will re-open if additional information is provided

@khalwat khalwat closed this as completed Apr 28, 2024
khalwat added a commit that referenced this issue Jun 20, 2024
…sed in `$critera`, which turned objects into sub-arrays in `orderBy` and other properties, causing a DB error ([#51](#51)) ([#50](#50))
khalwat added a commit that referenced this issue Jun 20, 2024
…sed in `$critera`, which turned objects into sub-arrays in `orderBy` and other properties, causing a DB error ([#51](#51)) ([#50](#50))
khalwat added a commit that referenced this issue Jun 20, 2024
…sed in `$critera`, which turned objects into sub-arrays in `orderBy` and other properties, causing a DB error ([#51](#51)) ([#50](#50))
@khalwat
Copy link
Contributor

khalwat commented Jun 20, 2024

Figured it out while looking into an unrelated issue. Fixed in the following releases:

Craft 3: https://github.com/nystudio107/craft-similar/releases/tag/1.1.7

Craft 4: https://github.com/nystudio107/craft-similar/releases/tag/4.0.2

Craft 5: https://github.com/nystudio107/craft-similar/releases/tag/5.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants