Skip to content

Override bundle entity mapping #7076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
psrpinto opened this issue Oct 21, 2016 · 0 comments
Closed

Override bundle entity mapping #7076

psrpinto opened this issue Oct 21, 2016 · 0 comments
Labels
actionable Clear and specific issues ready for anyone to take them. Doctrine hasPR A Pull Request has already been submitted for this issue.

Comments

@psrpinto
Copy link
Contributor

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?

@javiereguiluz javiereguiluz added the actionable Clear and specific issues ready for anyone to take them. label Nov 28, 2017
@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label Jul 12, 2018
javiereguiluz added a commit that referenced this issue Sep 7, 2020
This PR was merged into the 3.4 branch.

Discussion
----------

Remove paragraph about doctrine mapping override

Hello,

I would suggest to remove the paragraph about mapping override because it doesn't work in all cases.

I read the related PR (#10053) and the issue (#7076) which motivated it. The example in the issue works only because `auto_mapping` is set to `true` (`auto_mapping: true` allows to find definitions in `Resources/config/doctrine/*.orm.{xml, yml, php} of all the bundles even if nothing is declared in the bundles).

From the POV of the bundle , it's IMHO not a good practice to rely on app `auto_mapping` configuration (the trend for sf4 and sf5 is to rely on configurations over conventions).

So when bundle mapping rely on the dedicated compiler pass (example [here](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/cf7fe27b2f4e1f298ee6eadf537267f8c9f9b85c/FOSUserBundle.php#L50)) and not on `auto_mapping` app configuration , the mapping definition file in the compiler pass (from the bundle) overrides the mapping definition file defined in the application.

Commits
-------

49eca77 Remove paragraph about mapping override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. Doctrine hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

3 participants