使用KNP分页器的实体中的复合主键上不允许使用单个ID [英] Single id is not allowed on composite primary key in entity using knp paginator

查看:105
本文介绍了使用KNP分页器的实体中的复合主键上不允许使用单个ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对knp分页器有疑问。
我使用Symfony 2.8。
我使用knp分页器制作了一个包含复合主键和相应列表页面的表。
我尝试显示时收到例外。
实体中的复合主键上不允许使用单个ID
我试图检查knp分页器和学说的源文件。
所以我找到了解决方法。

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)将knp选项 distinct设置为false;

1)Set knp option "distinct" to false;

2)设置以下查询提示。

2)Set following hints to query.


  • 将 knp_paginator.count设置为查询结果的行数。

  • 将 knp_paginator.fetch_join_collection设置为false-这是必需的。

这是正确的方法吗?
是否存在潜在的问题?

Is this right way? Are there potential problems?

推荐答案

您可能遇到的问题发布在此处与GitHUB相关的问题

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


唯一的问题是当您的Paginator查询要求获取到集合的联接时。解决方法是使用如上所述的常规联接。缺点是您的分页实体将不会与集合水合。调用时,集合必须被延迟加载。

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.

这篇关于使用KNP分页器的实体中的复合主键上不允许使用单个ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆