nystudio107 / craft-similar

Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.
https://nystudio107.com/
MIT License
26 stars 5 forks source link

[FR] Support for eager loading through 'criteria' #14

Closed devanflaherty closed 3 years ago

devanflaherty commented 5 years ago

Hey there, Thank you for the awesome plugin, it accomplishes exactly what I was looking for!

I was curious if you were planning to support eager loading through the find() criteria attribute.

I have my $limitCriteria all set and have my eager loaded elements defined within ->with(), but it seems the way the method ends up getting each $model after the results have been found (by $elements->getElementById()) doesn't account for eager loading.

Supporting this would be awesome, but if that's not something on the horizon or maybe there is a reason it isn't accounted for please let me know!

khalwat commented 5 years ago

Added it as a FR -- I'm always open to pull requests!

Just looking at the code quickly, probably:

                $model = $elements->getElementById($config['id'], $elementClass, $config['siteId']);

...would need to be changed to an $elementClass::find() element query, which would have the added benefit of being able to do it all at once (by passing in the array of found IDs), and you could add the with there as well.

Maybe @svale has an interest?

svale commented 5 years ago

Sorry - happy to be mentioned, but probably not my field of expertise. (And apologies for the very late follow up.)

khalwat commented 3 years ago

This should be fixed in the dev-develop branch

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-similar": "dev-develop as 1.1.0”,

Then do a composer update

Let me know how you go...