Skip to content

Override bundle entity mapping #7076

Closed
Closed
@psrpinto

Description

@psrpinto

In the Entities & Entity Mapping section of How to Override any Part of a Bundle, the following is stated:

Due to the way Doctrine works, it is not possible to override entity mapping of a bundle. However, if a bundle provides a mapped superclass (such as the User entity in the FOSUserBundle) one can override attributes and associations.

I believe this is not completely true. If the bundle is defining the mapping in configuration files, it is possible to override the files, and thus the mapping. There is one caveat though: all mapping configuration files of the bundle must be overridden, you can't override just one of them.

I just tried it with JMSPaymentCoreBundle and it does work. I copied all the mapping files into app/Resources/config/JMSPaymentCoreBundle and then set the following configuration:

# app/config/config.yml

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    mappings:
        JMSPaymentCoreBundle:
            mapping: true
            type: xml
            dir: '%kernel.root_dir%/../app/Resources/config/JMSPaymentCoreBundle'
            alias: 'JMSPaymentCoreBundle'
            prefix: 'JMS\Payment\CoreBundle\Entity'

If I then alter something in one of the mapping files and run bin/console doctrine:schema:update, I can see my changes are there.

Would it be useful to clarify this in the docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoctrineactionableClear and specific issues ready for anyone to take them.hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions