Single id is not allowed on composite primary key in entity using knp paginator

若如初见. 提交于 2019-12-25 07:25:09

问题


I have a question about knp paginator. I use Symfony 2.8. I made a table that has composite primary key, and corresponding list page using knp paginator. I'm receiving the exception when I try to show. "Single id is not allowed on composite primary key in entity" I tried to inspect source files of knp paginator and doctrine. So I found a workaround.

1)Set knp option "distinct" to false;

2)Set following hints to query.

  • set "knp_paginator.count" to rows count of query result.
  • set "knp_paginator.fetch_join_collection" to false -- this is neccessary.

Is this right way? Are there potential problems?


回答1:


The problem you might encounter is posted here in this related issue on GitHUB:

The only "problem" is when your Paginator query calls for a fetch join to a collection. The work around for this is to use a regular join as mentioned above. The drawback is that your paginated entities will not be hydrated with the collection. The collection will have to be lazy-loaded when called upon.



来源:https://stackoverflow.com/questions/39542653/single-id-is-not-allowed-on-composite-primary-key-in-entity-using-knp-paginator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!