uuid_binary 表单验证错误:选项不存在或不唯一 [英] uuid_binary form validation error: The choice does not exist or is not unique

查看:26
本文介绍了uuid_binary 表单验证错误:选项不存在或不唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ramsey/uuid-doctrine 包将二进制 UUID 作为主键对于实体:

I'm using the ramsey/uuid-doctrine package to have binary UUIDs as primary key for an entity:

class Site
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="uuid_binary")
     */
    private $id;

    ...
} 

我需要为另一个实体构建一个表单,该实体在多对一关系中具有该实体.

I need to build a form for another entity which has that entity in a ManyToOne relation.

因此,我在表单构建器中添加了一个 EntityType,如下所示:

So I added, in my form builder, an EntityType as follows:

$builder->add('site')

一切正常,HTML 选择以 uuids 作为键,但是当我提交表单时,我收到此验证错误:

Everything works, the HTML select has the uuids as keys, but when I submit the form I get this validation error:

Symfony\Component\Validator\ConstraintViolation对象(Symfony\Component\Form\Form).children[站点] = 4a41b3c4-4299-11e6-b562-fc3fdb5f816d

Symfony\Component\Validator\ConstraintViolation Object(Symfony\Component\Form\Form).children[site] = 4a41b3c4-4299-11e6-b562-fc3fdb5f816d

原因:Symfony\Component\Form\Exception\TransformationFailedException无法反转属性路径站点"的值:选择4a41b3c4-4299-11e6-b562-fc3fdb5f816d"不存在或不唯一

Caused by: Symfony\Component\Form\Exception\TransformationFailedException Unable to reverse value for property path "site": The choice "4a41b3c4-4299-11e6-b562-fc3fdb5f816d" does not exist or is not unique

原因:Symfony\Component\Form\Exception\TransformationFailedException选项4a41b3c4-4299-11e6-b562-fc3fdb5f816d"不存在或不唯一

Caused by: Symfony\Component\Form\Exception\TransformationFailedException The choice "4a41b3c4-4299-11e6-b562-fc3fdb5f816d" does not exist or is not unique

<小时>

如果我这样做,在控制器中:


If I do, in a controller:

$this->getDoctrine()->getManager()
  ->getRepository('AppBundle:Site')->find('4a41b3c4-4299-11e6-b562-fc3fdb5f816d');

它确实找到了实体,所以它存在.

It does find the entity, so it exists.

推荐答案

我能找到的唯一 hack:我从请求中删除了字段值并稍后手动设置

Only hack I could find: I removed the field value from the request and manually set it later

$site_uuid = $_POST['smart_link']['site'] ?? null;

$request_link = $request->request->get('link');
$request_link['site'] = '';
$request->request->set('link', $request_link);

$form->handleRequest($request);

....

$link->setSite($em->getRepository('AppBundle:Site')->find($site_uuid));

这篇关于uuid_binary 表单验证错误:选项不存在或不唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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