首页 文章

在Symfony Doctrine ORM中指定实体类名称

提问于
浏览
0

我正在使用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中不起作用 .

1 回答

  • 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
    

相关问题