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

Fixed $model->countRelated() failing when the relation is reusable #14444

Merged
merged 11 commits into from
Oct 13, 2019

Conversation

zsilbi
Copy link
Member

@zsilbi zsilbi commented Oct 3, 2019

Hello!

  • Type: bug fix

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:

The uniqueKey used to store reusable related records in ModelsManager is currently generated only from the conditions used to lookup the records.

For example:
It uses the same key for $robot->getParts(["some" = "thing"]) and $robot->countParts(["some" = "thing"]).
If the related records are accessed again using a different method, it will return the result of the first.
In this case, it will be a Resultset instead of an integer.

I added the retrieveMethod variable to the uniqueKey generation.
Added some tests for Model::__call()

Thanks,
zsilbi

@zsilbi zsilbi changed the title [WIP] Fixed Model::countRelated() failing when the relation is reusable [WIP] Fixed $model->countRelated() failing when the relation is reusable Oct 3, 2019
@zsilbi
Copy link
Member Author

zsilbi commented Oct 12, 2019

@sergeyklay I'd also change Model::__callStatic() to throw an exception if the method is unknown, like Model::__call() does.

What do you think?

@niden niden added 4.0 wip Work In Progress labels Oct 12, 2019
@sergeyklay
Copy link
Contributor

@zsilbi Let's use a separated PR to change Model::__callStatic()

retrieve method (find, findFirst, count.. etc.)
New RobotsReusable model for testing reusable relation
null. Therefore it should return false, instead of null when the
requested method doesn't exist.
_getRelatedRecords returns null. Therefore it should return false,
instead of null when the requested relation doesn't exist.
@codecov
Copy link

codecov bot commented Oct 13, 2019

Codecov Report

Merging #14444 into 4.0.x will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##            4.0.x   #14444      +/-   ##
==========================================
+ Coverage   67.67%   67.68%   +0.01%     
==========================================
  Files         482      482              
  Lines      111229   111235       +6     
==========================================
+ Hits        75275    75294      +19     
+ Misses      35954    35941      -13

@zsilbi zsilbi changed the title [WIP] Fixed $model->countRelated() failing when the relation is reusable Fixed $model->countRelated() failing when the relation is reusable Oct 13, 2019
@niden niden added documentation Documentation required and removed wip Work In Progress labels Oct 13, 2019
@niden niden merged commit cf397d0 into phalcon:4.0.x Oct 13, 2019
@niden
Copy link
Sponsor Member

niden commented Oct 13, 2019

Thank you @zsilbi

@zsilbi zsilbi deleted the model-reusable-records branch October 14, 2019 07:57
@niden niden removed the documentation Documentation required label Dec 15, 2019
@niden niden added bug A bug report status: low Low and removed Bug - Low labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants