1

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

细节

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

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

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

检查 JSON 响应我注意到_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: ~

谢谢你。

4

1 回答 1

0

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

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

public function getId()
{
    return (string)$this->id;
}
于 2015-09-03T09:37:58.430 回答