gpt4 book ai didi

symfony - FosElasticaBundle:定义GUID/UUID字段的映射

转载 作者:行者123 更新时间:2023-12-03 00:19:42 24 4
gpt4 key购买 nike

如果我的实体使用GUID字段类型作为标识符,如何在config_yml中定义映射?

细节

我有一个使用Symfony 2.7.3和FosElasticaBundle 3.1.4的项目。

我已经配置了映射,并且当我使用populate命令或编辑现有实体时一切正常。但是在创建新实体时出现异常

"expected a simple value for field [_id] but found [START_OBJECT]]"

Checking the JSON response我注意到_id设置为空对象 ..."_id":{}...

Uuid 类已经有一个 __toString 方法,我希望它可以解决这个问题,但是我可能缺少了一些东西。

当前映射
fos_elastica:
clients:
default: { host: %elasticsearch_host%, port: %elasticsearch_port%, logger: true }
indexes:
app:
types:
user:
mappings:
name: ~
surname: ~
persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~

谢谢。

最佳答案

UUID / GUID字段没有特定的映射。

使用标准的Symfony属性访问器检索标识符,因此解决此问题的方法是更改​​实体中的getId()方法,并将其强制转换为字符串 be

public function getId()
{
return (string)$this->id;
}

关于symfony - FosElasticaBundle:定义GUID/UUID字段的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32098207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com