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

[ModelManager] Merging find parameters #11987

Closed
ghost opened this issue Jul 19, 2016 · 3 comments
Closed

[ModelManager] Merging find parameters #11987

ghost opened this issue Jul 19, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 19, 2016

Hi,

when using getRelated() method in a model with non-trivial find paramaters, for example while using OR in a condition, it behaves strangely and bad query is generated for me.

I think is an error on these lines:
https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/manager.zep#L1130
https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/manager.zep#L1151

and I think that $value should be wrapped inside brackets as well. Because related records have this implicit equality condition on foreign key columns.

But when using OR keyword inside parameters when calling getRelated() instead of condition like this:

[
    'conditions' => '<foreign-key-cond> AND (<cond1> OR <cond2>)'
]

is generated only this

[
    'conditions' => '<foreign-key-cond> AND <cond1> OR <cond2>'
]

Which is obviously wrong. This can be fixed manually by including the brackets in the condition:

return $this->getRelated('relatedAlias', [
    'conditions' => '(<cond1> OR <cond2>)' // without brackets it doesn't work
]);

But from the users point of the view it should be better to do it automatically. Because users do not need to know about any of the implicit conditions.

@Jurigag
Copy link
Contributor

Jurigag commented Jul 19, 2016

You can create PR with fix for it if you need it now.

@ghost
Copy link
Author

ghost commented Jul 19, 2016

OK, so here is the PR for review #11990

andresgutierrez added a commit that referenced this issue Jul 19, 2016
Fix for issue #11987 - merging conditions in manager.zep _mergeFindParameters method
@sergeyklay
Copy link
Contributor

Fixed in the 2.1.x branch. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants