-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add support for ManyToMany Criteria #885
Add support for ManyToMany Criteria #885
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-2868 We use Jira to track the state of pull requests and the versions they got |
@bakura10 tests! =) |
Yep yep. I'm just not sure of the approach yet, and I've found a bug :(. |
I've fixed the logic, however I have no idea about how to test this. Actually, there is no test for most persisters :(. |
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany associations at the moment."); | ||
if ($this->association['type'] !== ClassMetadata::ONE_TO_MANY | ||
&& $this->association['type'] !== ClassMetadata::MANY_TO_MANY) { | ||
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany and ManyToMany associations at the moment."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means it works for all PersistentCollection, as there are the only 2 types of toMany relations (and a toOne relation is not a collection). You should simply remove the exception
Please don't do multiple things at once. The lazy thing sounds very complicated, support for ManyToMany to start with would be awesome all alone. |
I think this PR does only one thing no? (Actually the other PR is MUCH more needed than this one :)) |
Tests no longer should break! |
Still breaks, plesae run the tests locally, just call |
I'm not sure to understand, all tests pass without any problem locally :/. |
Furthermore the failing tests on Travis have nothing to do with my changes :/. |
Some errors I had locally then were because of an older DBAL. I leo updated DBAL and now all tests pass locally, so I don't really understand. EDIT : this is actually passing, it seems there was an error with one stack on Travis. |
I really really need this. What do you want me to do in order to merge? :) |
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany associations at the moment."); | ||
if ($this->association['type'] === ClassMetadata::MANY_TO_MANY) { | ||
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); | ||
return new ArrayCollection($persister->loadCriteria($this, $criteria)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty newline before this line
@bakura10 a rebase is needed, plus I'm not sure about what kind of coverage you get with the current tests... |
Hi, I've fixed the CS and added a functional test. However, it fails! In fact, the SQL query that is executed is perfectly right, however the hydration does not work. I'm not confident enough about how ResultSetMapping and hydrators work, so a bit of help would be appreciated. I think this is the problem: https://github.com/doctrine/doctrine2/pull/885/files#diff-982b7374bbe9d5f4b6b71f4869a446eaR512 |
👍 on this, super useful |
Anyone can help me on the issue I'm having? Sorry for being a bit persistent on this one but this is really useful ! |
@FabioBatSilva do you know if this clashes with SLC? |
Hi, I've been doing more debugging. I can confirm that the SQL queries is generated correctly, and manually calling "fetchAll" from the prepared statement correctly returns the wanted rows. Where it fails is indeed in the hydrator. The method "gatherRowData" from ObjectHydrator returns an empty array. I'm not sure why, but when I compared with other results, the query returns result like this: array(4) {
'id' =>
string(1) "1"
'name' =>
string(12) "Developers_0"
'user_id' =>
string(1) "1"
'group_id' =>
string(1) "1"
} This contains both the columns from the table and from the join table, but none of the columns are suffixed by an number (like "id0", "name1"...) and I suppose the hydrator must reuse this info to map those things to objects using the ResultSetMapping. Any idea @beberlei ? |
I've finally made it by using the ResultSetMappingBuilder!!! Could someone have a look at the approach (performance wise)? Only one test is failing locally but it seems it has nothing to do with my PR. |
@Ocramius could you give this one a quick review please? To me it's ready to be merged :). |
* | ||
* @return array | ||
*/ | ||
public function loadCriteria(PersistentCollection $collection, Criteria $criteria); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bakura10 Shouldn't the contract here be to throw an exception if the operation is unsupported by the implementing collection persister? IMO that should be documented here as you already do throw an exception in AbstractCollectionPersister
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mimic the other methods. All the other methods (slice, containsKey...) throw an exception in the AbstractCollectionPersister but it's not in the interface. I just followed the same pattern, if I add it here I should also add it for all other methods then :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bakura10 Okay I didn't know that. Then it's perfectly fine to me, no need to go a different way here then :)
Rebased @beberlei |
Tests are all passing, only one just did not execute. Can someone relaunch tests so that Travis goes green? :) |
Hi, It seems someone relaunched the tests, and everything is passing now. What is preventing this to being merged, so that I can eventually work on it quickly? |
👍 |
Add support for ManyToMany Criteria
Awesome, thanks! |
This replaces #773
It adds support for ManyToMany but also do an efficient filtering instead of loading the whole collection. I think it can also benefits from #882 when this one get merged.