【问题标题】:Duplicate definition of column 'username' on entity FOSUserBundle FOSRestBundle JMSSerializerBundle实体 FOSUserBundle FOSRestBundle JMSSerializerBundle 上列“用户名”的重复定义
【发布时间】:2014-10-22 18:52:11
【问题描述】:

我正在尝试将 FOSUserBundle 与 FOSRestBundle 和 JMSSerializer 一起使用。

我已成功使 RESTFul 模块正常工作,因此我能够访问 /api/v1/users/ 但是它从 FOSUserBundle 返回所有 DB 字段,我希望能够指定要提供哪些字段。

通过将@Expose 添加到相应模块实体中的注释中,我已经在我的其他模块上工作了。但是,我可以看到 FOSUserBundle 没有实体,并且在尝试创建自己的实体(如下提供)时,它会引发此异常:

MappingException:字段或鉴别器列映射中实体“CYLO\UserBundle\Entity\User”上列“用户名”的重复定义。

任何帮助表示赞赏。

【问题讨论】:

    标签: php symfony twig fosuserbundle fosrestbundle


    【解决方案1】:

    您需要为类 FOS\UserBundle\Model\User 提供序列化定义。例如,使用名为 Model.User.yml 的 YAML 文件:

    FOS\UserBundle\Model\User:
        exclusion_policy: ALL
        properties:
            id:
                expose: true
            username:
                expose: true
            email:
                expose: true
    

    然后像这样配置jms序列化器:

    jms_serializer:
        metadata:
            auto_detection: false
            directories:
                FOSUserBundle:
                    namespace_prefix: FOS\UserBundle
                    path: "@MyOwnBundle/Resources/config/serializer"
                    ...
    

    【讨论】:

    • 谢谢,我知道这很简单。
    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 2014-01-08
    • 2017-12-20
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多