-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Model relation reusable=>false not working #13531
Comments
I've dug around in the source code and am pretty sure that this is the cause of the problem: https://github.com/phalcon/cphalcon/pull/11983/files Once accessed, the related records are stored as an instance property and returned every time, regardless of what 'reusable' is set to. |
Why it should requery? After first getting it it adds as a property, this is intended to keep behavior with magic properties. You can use getParts for example(and you imh should). |
@Jurigag I would expect it to requery because reusable is false. I do not see from the documentation that some access methods are intended to behave differently to others. Also in Phalcon 2 it does requery when using the magic getter and I suspect the change in behaviour was an unintended consequence of the pull request I linked to? |
Just to add more info: getParts() and getRelated('Parts') both respect the 'reusable' setting in the relation. This is a change compared to behaviour in Phalcon 2. It was introduced by, I think, #11983 - and I think it's most likely unintentional and undocumented. |
I think this is intentional to keep behavior with magic properties etc. |
Thanks Jurigag - what do you think about the way it's changed from Phalcon 2 to Phalcon 3? It does requery (depending on the reusable setting) in Phalcon 2, even when using ->Parts. This is causing lots of upgrade problems for us - but it also makes me think that it's a bug, as the behaviour has changed without being documented. |
I think as i already wrote, this change was made to keep behavior how magic properties works in php world, like in 90% of magic properties stuff, when first access them __get is fired and on later accessing the same property we already use property we added in __get. |
I disagree @Jurigag. I noticed this when I created the PR for the |
@niden this is a bug |
Resolved in #14035 |
Expected and Actual Behavior
I have a model with a relation set to 'reusable' => false.
I would expect the relation to be fetched from the database every time it is accessed.
However the relation is cached after the first call, even though 'reusable' => false.
Using 'getRelated()' to access the relation works as intended.
Note: 'reusable' => false is the default setting, so models do not work as intended by default.
Here is some sample code:
Severity
Critical - this is stopping us from upgrading to Phalcon 3 + model relations do not work as documented.
Details
The text was updated successfully, but these errors were encountered: