0

I'm using YAML for configuring the Doctrine ORM mappings in Symfony 4. Is there any way to specify the class name of an entity manually in its config? It seems like the entity's class name is generated based on the name of the yml config file and there is no way to override it.

Say I have a mapping config called Foo.orm.yml. Doctrine is going to think that the actual name of the entity class is Foo. But what if I want the Foo.orm.yml file to map the table onto the class Bar? So I was thinking about something like the class option inside the config, but haven't found anything on the Internet.

#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 mappings have the name option though: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/xml-mapping.html which doesn't work in YAML.

1 Answer 1

1

Change Bar to AppBundle\Entity\Bar

AppBundle\Entity\Bar:
    type: entity
    table: bar
    id:
        id:
            type: integer
            generator: { strategy: NONE }
    fields:
        foo:
            type: string
        bar:
            type: boolean
Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't work. Doctrine bundle ignores this top-level key.
This is how I use it in my projects (3.4)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.