Skip to content

Conversation

@xrash
Copy link
Contributor

@xrash xrash commented Oct 8, 2014

I was facing a bug while paginating a Doctrine entity that had a composite primary key and getting this exception:

Single id is not allowed on composite primary key in entity [...]

After poking in the code, I actually found that the exception was being thrown by Doctrine, and there was already a test for that. To my amusement, the test was passing. I tried to do in my code exactly what the test was doing, but no dice.

So I poked a little bit more and discovered that the CompositeKeyTest was running with an empty schema, and that's why it succeded and my code didn't. It took me to just populate the testing schema with some fixtures for the test to fail just like my code.

After a while, I was able to make it work using some crazy hint which I am not sure if it works generally, but worked for me.

Can you guys help to check if those changes make sense at all?

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

so if run test with $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, false); and populate fixtures we should get Single id is not allowed on composite primary key in entity [...] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if you "should" get that in the sense of expected behavior, but that's what is happening.

@lunetics
Copy link

stumbled across the same problem, what did you do to make it work @xrash ?

@xrash
Copy link
Contributor Author

xrash commented Feb 19, 2015

@lunetics Try using these options:

$query->setHint('knp_paginator.count', $count);
$query->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false);
$options = array('wrap-queries' => true);
$result = $paginator->paginate($query, $page, $limit, $options);

@lunetics
Copy link

hey @xrash thanks. that finally works with wrap-queries.

I Think the problem lies, that even if you supply the "knp_paginator.count", the doctrine pagintor still has a 0 count and "tries" to build a count query (which fails because of composite primary key).

But i'm not so deep into that, so i think maybe someone should look over that.

@lunetics
Copy link

Just saw, even when supplying a count, the doctrine count query is initiated!

@xrash
Copy link
Contributor Author

xrash commented Feb 19, 2015

@lunetics, that's a nice reasoning.

It looks like the behavior when dealing with composite keys is actually documented here, so it's more like a "lack of feature" instead of a bug. However, I think that the solution proposed in the documentation does not work, so we should also update the docs and/or implement this feature.

I will try to have a look on that soon enough, but still this PR makes sense alone by itself (in the current state of things) and the docs are in another repo. Also, this PR is kinda like dead =p.

@l3pp4rd l3pp4rd merged commit bc49e73 into KnpLabs:master Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants