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

Expose EntityPersister::count() through EntityRepository::count() #6003

Closed
wants to merge 4 commits into from

Conversation

phansys
Copy link
Contributor

@phansys phansys commented Sep 2, 2016

Q A
Branch master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

TODO:

  • Add tests.
  • Add documentation.

@phansys phansys force-pushed the entity_repo_count branch 4 times, most recently from 584dc0c to 3a41091 Compare September 4, 2016 20:06
@Ocramius
Copy link
Member

Ocramius commented Sep 7, 2016

I personally don't like overloading the repositories with even more functionality, but this might actually be useful.

Thoughts, @guilhermeblanco @beberlei @deeky666 @kimhemsoe?

@@ -41,7 +41,7 @@ headline "Hello World" with the ID 1234:
<?php
$article = $entityManager->find('CMS\Article', 1234);
$article->setHeadline('Hello World dude!');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't trim whitespace: it is in place due to RST here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @Ocramius, I'll revert these changes.

@carnage
Copy link
Contributor

carnage commented Sep 7, 2016

I would probably have assumed this feature already existed if asked. From that perspective I think it makes for a good addition.

Perhaps use a rebase --interactive to clean up the change then revert of whitespace changes to the docs.

@phansys
Copy link
Contributor Author

phansys commented Sep 7, 2016

Sure @carnage, when the PR is ready to merge I'll perform a rebase.

@mnapoli
Copy link
Contributor

mnapoli commented Sep 7, 2016

👍 that would avoid having to write a DQL query for a simple count (unless I'm completely wrong?)

@phansys
Copy link
Contributor Author

phansys commented Sep 7, 2016

Yes @mnapoli, this is the intended goal.

case 4:
return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);

default:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if this statement is here intentionally (just for the comment) or if this can be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@asgrim
Copy link
Contributor

asgrim commented Sep 7, 2016

LGTM 👍 (would use a +1 thing but I'm on mobile, sorry)

case 3:
return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);

case 4:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we support only PHP 5.6+, then we can simply do return $this->$method([$fieldName, $arguments[0]), ...array_slice($arguments, 1))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yep, we only support 5.6+

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll apply this on merge: merging and moving forward from master myself :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I squash now then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope: already checked out locally and took ownership of the branch. Relax, sit back and have a 🍺


$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));

if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should throw an exception when this is not true: move the exception throwing up :-)

@Ocramius Ocramius self-assigned this Sep 7, 2016
@Ocramius Ocramius added this to the 2.6.0 milestone Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
Ocramius added a commit that referenced this pull request Sep 7, 2016
@Ocramius Ocramius closed this in 8a87fa2 Sep 7, 2016
@Ocramius
Copy link
Member

Ocramius commented Sep 7, 2016

@phansys merged, thanks!

@phansys phansys deleted the entity_repo_count branch September 8, 2016 13:15
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
yvoyer pushed a commit to yvoyer/doctrine2 that referenced this pull request Nov 21, 2016
@teohhanhui
Copy link
Contributor

@phansys @Ocramius The documentation needs to state New in version 2.6.

I was surprised when I saw it, because I remember there was no such function. 😂

@Ocramius
Copy link
Member

@teohhanhui sorry, our docs are indeed terribly versioned, as it stands (website publishes current master). Please consider helping us in fixing that at https://github.com/doctrine/doctrine-website-sphinx

teohhanhui added a commit to teohhanhui/doctrine2 that referenced this pull request Feb 17, 2017
@teohhanhui
Copy link
Contributor

@Ocramius Is #6294 going to render fine?

@vudaltsov
Copy link
Contributor

This is such an unexpected BC-break for those who implemented this method on their own like I did...

@Majkl578
Copy link
Contributor

Adding new public method is not a BC break per se. BC break is an unexpected change of behavior or existing API. Even Symfony, known for its BC promise, won't give you guarantee when it comes to extending a class and adding new methods: https://symfony.com/doc/current/contributing/code/bc.html

@vudaltsov
Copy link
Contributor

@Majkl578 , okay. But extending EntityRepository is a really popular practice. Naming method count() also makes a lot of sense. See above, there are already two PRs fixing this and I am sure, we'll see more tomorrow.

@Ocramius
Copy link
Member

I don't see how this is a BC break: yes, it raises a warning if you subclassed and had different signature, but that makes it easy to migrate whilst maintaining it working.

And yes, that basically clarifies my initial doubts: no more EntityRepository features ever.

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

Successfully merging this pull request may close these issues.

8 participants