-
-
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
Fixed saving a model after fetching its related records #13985
Fixed saving a model after fetching its related records #13985
Conversation
Added specific tests for issue phalcon#13964.
Codecov Report
@@ Coverage Diff @@
## 4.0.x #13985 +/- ##
=========================================
- Coverage 67.9% 67.9% -0.01%
=========================================
Files 469 469
Lines 94291 94290 -1
=========================================
- Hits 64032 64031 -1
Misses 30259 30259
Continue to review full report at Codecov.
|
I will keep this open for a some time to allow other contributors a chance to speak up, and to take a fresh look at it later. But at the moment it seems good to me. /cc @phalcon/framework-team |
@zsilbi can you update the changelog when you get a chance please and rebase. Thanks! |
Added specific tests for issue phalcon#13964.
…ng-related' into T13964-saving-model-after-fetching-related
We need another test as it looks like this removed functionality. I'm not sure with regards to the run-time exception or what was generating ... but this is likely not the right fix as this will break caching. Need to query a related record multiple times and ensure the database is only hit once. In this case, it will be re-queried every time when you remove that line. |
|
Thank you @zsilbi |
Well now
If a runtime exception is being thrown somewhere ... the fix is to not UNCOMMENT a line .. it's to fix the issue where the exception is being thrown and explain it properly with tests. This needs to not be merged @niden. Revert please :) until a more thorough analysis can be done with proper tests showing this won't all of a sudden overwhelm production stacks that use getters for related items all over not expecting the database to be hit everywhere. |
@virgofx it's a different issue then because if you query the items via If you investigate further you will notice that this related storage is only used before and after updating a models related records. Only if this storage is empty |
…)" This reverts commit df63851.
Just reverted this PR from 4.0.x branch |
@zsilbi Feel free to discuss the issue here and re-send a new one, again if the need arises |
@zsilbi I'm not disagreeing that the original implementation is poor. If we're going to remove the related ... it should be removed everywhere and we should have tests to account for what I described above. It's still being used when setting related items and checking if it's loaded. So if we're going to remove the 1 - getting related 5 - if we do this .. .it's also breaking (fine for 4.0) ... just need to make aware people that extend the Model class with custom relations/logic (I do this myself) so the comments need to be updated to reflect this more thoroughly in the 4.0 upgrade log as well. |
Ok guys, I've done some research to get the complete picture about the purpose of In #12772 @Surt mentoined that the former I am not sure if @CameronHall had been aware of this in #13616 when he'd added that line that I commented here. When Also, this related storage problem needs to be redone together with issue #13531, as storing objects only in properties as a cache and using Please advise. |
Like I said ... the related records is very finicky and any changes will either be super minor ... or a refactor and need to cover the cases I've mentioned above. We have to be very careful because I have made changes in extending models and small changes like this cause issues where repeat queries kill production servers .... from an end-users application logic ... they may want to use |
I agree |
Hello!
In raising this pull request, I confirm the following:
Small description of change:
I've added some tests to check if this issue exists at all.
The tests failed, so added a fix in a previous PR (#13970) but ran into a conflict so I made a new PR.
The problem is, that the related models are stored in the
_related
storage inside Model after accessing via__get()
. It is not stored when accessing related records via__call()
.When the model is saved,
_postSaveRelatedRecords
is being called and it iterates through_related
and tries to save the previously fetched related records.For now, I just removed adding these records to the
_related
as it's not mandatory when you are only reading them.Thanks