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

Change serialization of inheritance fields #1556

Merged

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Feb 1, 2017

Fixes #1271.

The previous solution would always require specifying an inheritance type, which makes sense for documents but seems weird for embedded documents. With this PR, this changes to serialize the inheritance information (inheritance type and discriminator data) if an inheritance type was specified or if the discriminator field was given. This should fix hard to find cases where data can't be stored or loaded once the metadata was loaded from cache.

@alcaeus alcaeus force-pushed the serialize-inheritance-fields-embedded-docs branch from 508b3ea to 20da3ee Compare February 1, 2017 14:43
@alcaeus alcaeus changed the title Serialize inheritance information for embedded documents Change serialization of inheritance fields Feb 1, 2017
@alcaeus alcaeus force-pushed the serialize-inheritance-fields-embedded-docs branch from 20da3ee to 7ad4804 Compare February 1, 2017 14:46
@Bilge
Copy link
Contributor

Bilge commented Feb 20, 2017

Is there any reason not to merge this?

@alcaeus alcaeus requested a review from malarzm February 20, 2017 15:21
@@ -123,7 +123,7 @@ public function __sleep()
$serialized[] = 'customRepositoryClassName';
}

if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE) {
if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE || $this->discriminatorField !== null) {
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it be better to check for being embedded document's metadata? Otherwise the issue still persists when not using discriminatorField which I think can be null to default to _doctrine_class_name later down the line? Please take this with a grain of salt though, I'm always confused by class metadata's defaults

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, didn't think about _doctrine_class_name - especially since that doesn't involve a map either. Will have to investigate.

Copy link
Member

Choose a reason for hiding this comment

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

Actually I think that map can be combined with default discriminator field since it only provides string <=> FQCN mapping ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

After looking at the code, this looks safe: _doctrine_class_name is not used at the class level, which this PR is trying to fix. Instead it's used when an association contains no targetDocument and no discriminatorField has been set - in this case the discriminatorField is simply set to _doctrine_class_name as if it were used in the mapping. I think we should be safe merging this.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@malarzm malarzm added the Bug label Mar 8, 2017
@malarzm malarzm added this to the 1.1.4 milestone Mar 8, 2017
@malarzm malarzm merged commit e96bfba into doctrine:1.1.x Mar 8, 2017
@alcaeus alcaeus deleted the serialize-inheritance-fields-embedded-docs branch July 3, 2017 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants