-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Added a way to enable auto_mapping option using multipe entity managers #321
Conversation
{ | ||
$definedBundles = array_keys($container->getParameter('kernel.bundles')); | ||
|
||
foreach ($entityManagerConfigs as $name => &$entityManager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd completely reverse the order of your foreach here. I'd loop through definedBundles and find an EM that is the candidate for mapping, not an O(n^3) solution. I assume that multi-auto_mapping should be verified somewhere else, not when deciding the bundles mapping.
It would turn your algorithm into something like this:
private function validateORMAutoMapping(array $entityManagerConfigs)
{
$emAutoMapping = null;
foreach ($entityManagerConfigs as $name => $entityManager) {
if ( ! (isset($entityManager['auto_mapping']) && $entityManager['auto_mapping'])) {
continue;
}
if ($emAutoMapping && $emAutoMapping !== $name) {
throw new \LogicException(sprintf('You cannot enable "auto_mapping" on more than one entity manager at the same time (found in "%s" and %s").', $emAutoMapping, $name));
}
$emAutoMapping = $name;
}
}
private function collectAutoMappings(array $entityManagerConfigs, array $bundles)
{
foreach ($bundles as $bundle) {
$emCandidate = null;
foreach ($entityManagerConfigs as $name => &$entityManager) {
// Specific bundle mapping
if (isset($entityManager['mappings'][$bundle])) {
$emCandidate = $entityManager;
break;
}
// Check for auto-mapping
if ( ! (isset($entityManager['auto_mapping']) && $entityManager['auto_mapping'])) {
continue;
}
$emCandidate = $entityManager;
}
// If we could resolve at least one EM
if ($emCandidate) {
$emCandidate['mappings'][$bundle]['mapping'] = true;
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a lot of complex logic, that imho should better be in the abstract base class, which is what I did. then again this solution is backwards compatible with earlier Symfony versions I guess.
I have committed the changes proposed by @guilhermeblanco |
@@ -331,6 +331,10 @@ protected function ormLoad(array $config, ContainerBuilder $container) | |||
|
|||
$container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager'])); | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra new line
the question is if this code should not get pushed to the DoctrineBridge in Symfony, since the ODM bundles will need this code too. |
Unfortunately I have zero experience with odm, but Monday I will try to take a look! |
@lsmith77 I can't see a clean solution how to move this code to DoctrineBridge... My first idea was to move First implementation: Do you have some suggestions? |
@goetas DoctrineBundle already depends on DoctrineBridge currently. |
@stof Can it be merged (in the next future)? |
👍 |
$emAutoMapping = null; | ||
|
||
foreach ($entityManagerConfigs as $name => $entityManager) { | ||
if ( !isset($entityManager['auto_mapping']) || !$entityManager['auto_mapping']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the isset
is useless. It will always be set thanks to the way the Configuration class normalizes the config.
Hi! |
for BC you should do something like what I did in doctrine/DoctrinePHPCRBundle#167 |
why not add |
@goetas I don't want to need supporting 2 versions of the bundle. We need to keep supporting the 2.3 LTS until its EOL |
Added the BC commit |
…ping feature (goetas) This PR was squashed before being merged into the 2.6-dev branch (closes #11815). Discussion ---------- Added some methods to improve the handling of auto_mapping feature | Q | A | ------------- | --- | Bug fix? |no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | doctrine/DoctrineBundle#60 | License | MIT This PR is a part that is required by: * doctrine/DoctrineMongoDBBundle#267 * doctrine/DoctrineBundle#321 The proposed PRs are an alternative to #11650 and doctrine/DoctrineBundle#322 Commits ------- 2e30a43 Added some methods to improve the handling of auto_mapping feature
…ping feature (goetas) This PR was squashed before being merged into the 2.6-dev branch (closes #11815). Discussion ---------- Added some methods to improve the handling of auto_mapping feature | Q | A | ------------- | --- | Bug fix? |no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | doctrine/DoctrineBundle#60 | License | MIT This PR is a part that is required by: * doctrine/DoctrineMongoDBBundle#267 * doctrine/DoctrineBundle#321 The proposed PRs are an alternative to symfony/symfony#11650 and doctrine/DoctrineBundle#322 Commits ------- 2e30a43 Added some methods to improve the handling of auto_mapping feature
do your tests require 2.6? https://travis-ci.org/doctrine/DoctrineBundle/jobs/34889877#L189 |
@lsmith77 I think that i should skip the test if |
yup |
Squashed and tested against 2.6 |
ready to merge then .. |
@stof seems to be like you are the chief merger on this Bundle .. I do have the shiny green button but do not want to get into the way of things. |
|
||
if (!method_exists($loader, 'fixManagersAutoMappings')) { | ||
$this->markTestSkipped('Auto mapping with multiple managers available with Symfony ~2.6'); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the return statement should be removed. It is dead code (markTestSkipped
is throwing an exception to interrupt the test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, actually, I will do it myself.
It took time, but here we go, this is in now. Thank you very much @goetas. |
…entity managers (goetas) This PR was merged into the 1.3.x-dev branch. Discussion ---------- Added a way to enable auto_mapping option using multipe entity managers Finally, I fond some time to create this PR. This should close #60 I've also added a small test. Feedbacks are welcome! (if merged, this will require some lines on SF documentation...) Commits ------- 18fc82f Added a way to enable auto_mapping option using multipe entity managers
Thanks everybody! |
A huge thank you! |
@stof: do you know if this will make it into 1.3 and will there be a new 1.3 beta soon? Once again, thanks a lot! |
People, I can't find how to activate that for Symfony use. Any suggestions? Is there any new docs about how to do it? |
Finally, I fond some time to create this PR. This should close #60
I've also added a small test. Feedbacks are welcome!
(if merged, this will require some lines on SF documentation...)