Skip to content
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

use XML instead of annotations for Doctrine mapping to allow overriding it #20

Merged
merged 2 commits into from
Apr 13, 2017

Conversation

craue
Copy link
Owner

@craue craue commented Apr 16, 2015

Resolves #19. I've chosen XML over YAML to avoid a new dependency to symfony/yaml.

@rvanlaak: Could you try this to make sure the mapping can actually be overridden as expected?

@rvanlaak
Copy link
Contributor

I've chosen XML over YAML to avoid a new dependency to symfony/yaml.

The bundle is already relying on symfony/symfony so that dependency already is available

@craue
Copy link
Owner Author

craue commented Apr 16, 2015

The bundle is already relying on symfony/symfony so that dependency already is available

Only as a dev requirement.

@craue craue force-pushed the doctrine-mapping-xml branch 2 times, most recently from 13b181d to 50e07a1 Compare April 20, 2015 09:36
@craue
Copy link
Owner Author

craue commented Apr 21, 2015

@rvanlaak: Fine to merge?

@rvanlaak
Copy link
Contributor

Will check the PR branch later today

@rvanlaak
Copy link
Contributor

Update 1: everything is working fine after switching to the XML annotations.

Will try to override the XML mapping now.

@rvanlaak
Copy link
Contributor

Doctrine tries to drop the UNIQUE index:

DROP INDEX UNIQ_B95BA9425E237E06 ON craue_config_setting;

@rvanlaak
Copy link
Contributor

Next to that, Doctrine won't allow us to override the entity without creating a super-class:
http://symfony.com/doc/current/cookbook/bundles/override.html#entities-entity-mapping
In other words, moving to XML won't solve this problem.

We should make the config class a parameter, in the way how Sylius allows to override models:
http://docs.sylius.org/en/latest/bundles/general/overriding_models.html

@craue
Copy link
Owner Author

craue commented Apr 22, 2015

...or introduce a mapped superclass? I've added a commit for that. I now actually like the idea of being able to provide several mappings (ORM, ODM) and using dedicated files (XML or YAML) for that seems most convenient. A class config parameter could be added, but I guess this PR would still be needed in such case. Anyway, this is all new for me, so don't hesitate to prove me wrong. 😏

Doctrine tries to drop the UNIQUE index

Are you sure it's due to this PR? I cannot reproduce that.

@rvanlaak
Copy link
Contributor

A class config parameter could be added,

Without that I don't see a way to let your Bundle use the Entity located in my application. Maybe add some docs about extending the Settings entity with some example code?

but I guess this PR would still be needed in such case.

Definitely! 👍

@craue
Copy link
Owner Author

craue commented Apr 23, 2015

I made the class configurable and added a test, but there's one thing I don't have a solution for yet: The mapping file (Tests/IntegrationTestBundle/Resources/config/doctrine-mapping/CustomSetting.orm.xml) for the custom (overridden) class needs to be loaded, if one is used. Any idea how to achieve that?

@rvanlaak
Copy link
Contributor

Will pull the changes and take a look into that within the hour 👍

http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html#inheritence-mapping-overrides

@rvanlaak
Copy link
Contributor

Hmm, did find the "things to note" in this chapter:

http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html#attribute-override

@craue
Copy link
Owner Author

craue commented Apr 23, 2015

Are you pointing to something special? Looks like all this stuff (overriding parts of a model, extending a model, supporting multiple drivers) is not as easy as I thought.

@rvanlaak
Copy link
Contributor

Yeah, the following:

The column type CANNOT be changed. If the column type is not equal you get a MappingException

@craue
Copy link
Owner Author

craue commented Apr 23, 2015

And you want to change the type of the value field, right? 😏
If so, we cannot use/provide a mapped superclass and have to force users into specifying the complete mapping for the model. I don't like that idea and hope there's another way...

@rvanlaak
Copy link
Contributor

@beberlei is there any chance overriding attribute types will become possible in the near future?

@rvanlaak
Copy link
Contributor

This will probably only work if value is moved from the BaseSetting to the Setting entity. An extra interface is needed to ensure value is implemented.

Then I can determine the way how value looks in my own application, without overriding anything.

@craue
Copy link
Owner Author

craue commented May 4, 2015

This will probably only work if value is moved from the BaseSetting to the Setting entity.

I tried that locally but still couldn't get the mapping file loaded for the test.

An extra interface is needed to ensure value is implemented.

What do you mean? SettingInterface already has methods setValue and getValue.

@craue
Copy link
Owner Author

craue commented Jun 1, 2015

If there's no way to make this work, I'm forced to drop that idea completely.

@craue
Copy link
Owner Author

craue commented Apr 4, 2017

@rvanlaak, I started another approach and could finally make it work. 😄 Please take a look.

@rvanlaak
Copy link
Contributor

rvanlaak commented Apr 4, 2017

Oh wow really, that would be awesome! So then we finally can make the config a text instead of a varchar field? ;)

I'm now looking into a nice way to make these configurations translatable / internationalizable :-)

@craue
Copy link
Owner Author

craue commented Apr 4, 2017

I just made one more change to render the built-in form fields as textarea when the overridden entity maps the field value to a text column.

I'm now looking into a nice way to make these configurations translatable / internationalizable :-)

Luckily out of the scope of this PR. 😏

@coveralls
Copy link

coveralls commented Apr 4, 2017

Coverage Status

Coverage decreased (-0.3%) to 95.161% when pulling 4efac97 on doctrine-mapping-xml into 59ce2c0 on master.

@craue
Copy link
Owner Author

craue commented Apr 12, 2017

@rvanlaak, are any further changes needed or do you want me to just push the merge button? 😏

Copy link
Contributor

@rvanlaak rvanlaak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is ready for merge. Did place some minor comments, mainly related to removing year numbers ;-)


/**
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2017 Christian Raue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advise you to remove the years, to prevent you to have a task on January 1st.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the year for now. It's not a big deal to perform a search and replace once a year. 😆

->thenInvalid('The driver "%s" is not supported. Please choose one of ' . json_encode($supportedDrivers))
->end()
->end()
// when at least two values are defined (Symfony < 3.1 throws an exception with only one value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code can be removed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added a TODO task instead.

<?xml version="1.0" encoding="UTF-8" ?>
<!--
Author: Christian Raue <christian.raue@gmail.com>
Copyright: 2011-2017 Christian Raue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about the year here ;)

@@ -16,17 +16,17 @@
}
],
"require": {
"php": "^5.3.2|~7.0",
"symfony/framework-bundle": "~2.3|~3.0"
"php": "^5.3.9|~7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this PR release 2.0 of this bundle? If so, what about bumping it to >=5.5.9?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess 2.0 can be released soon, yes. But I'd like to keep Symfony 2.7 compatibility.

@coveralls
Copy link

coveralls commented Apr 13, 2017

Coverage Status

Coverage decreased (-0.3%) to 95.161% when pulling 3f447e1 on doctrine-mapping-xml into d33f2d8 on master.

@craue craue merged commit e661a70 into master Apr 13, 2017
@craue craue deleted the doctrine-mapping-xml branch April 13, 2017 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move Entity configuration to separate yml file
3 participants