stibiumz / phalcon.eager-loading

Solves N+1 query problem in Phalcon Model
The Unlicense
36 stars 24 forks source link

Phalcon >= 2.0.4 conditions on relationships #8

Open Surt opened 8 years ago

Surt commented 8 years ago

Since Phalcon 2.0.4 it's possible to write conditions on relationships 2.0.4 changes, under Relationships with conditionals

But it seems to fail when using the Loader

$users = Loader::fromResultset($users, ['favouriteImage']);

been favouriteImage a relationship with conditional it does not ask for the condition, only the relationship. Of course, actually the loader allows to override the relationship with the Querybuilder, but I will like to avoid this since my domain logic and data providers become a mess.

Again, thank you very much @stibiumz for your library, it does the phalcon orm more useful.

josefguenther commented 8 years ago

I can confirm, conditions do not work. The following is how it should work:

$this->hasMany('id', 'RobotsParts', 'robots_id', [
    'params' => ['conditions' => 'something = 1']
]);
erisrayanesh commented 6 years ago

Grate library @stibiumz . Same issue. I think before the line blow https://github.com/stibiumz/phalcon.eager-loading/blob/b3028a9ac828a2945bf9859a72b2a7667acd65a9/src/EagerLoading/EagerLoad.php#L133 you need to process the params part of relation options