【问题标题】:Specify entity class name in Symfony Doctrine ORM在 Symfony Doctrine ORM 中指定实体类名称
【发布时间】:2018-08-18 04:07:07
【问题描述】:

我正在使用 YAML 在 Symfony 4 中配置 Doctrine ORM 映射。有没有办法在其配置中手动指定实体的类名?看起来实体的类名是根据 yml 配置文件的名称生成的,没有办法覆盖它。

假设我有一个名为 Foo.orm.yml 的映射配置。 Doctrine 会认为实体类的实际名称是Foo。但是如果我想让Foo.orm.yml 文件将表映射到Bar 类上呢?所以我在考虑配置中的class 选项,但在互联网上没有找到任何东西。

#file Foo.orm.yml

Bar:
    class: Bar
    type: entity
    table: bar
    id:
        id:
            type: integer
            generator: { strategy: NONE }
    fields:
        foo:
            type: string
        bar:
            type: boolean

虽然 XML 映射有 name 选项:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/xml-mapping.html 在 YAML 中不起作用。

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    Bar 更改为 AppBundle\Entity\Bar

    AppBundle\Entity\Bar:
        type: entity
        table: bar
        id:
            id:
                type: integer
                generator: { strategy: NONE }
        fields:
            foo:
                type: string
            bar:
                type: boolean
    

    【讨论】:

    • 它不起作用。 Doctrine bundle 忽略了这个顶级键。
    • 这就是我在项目中使用它的方式(3.4)
    猜你喜欢
    • 2022-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多