zoopcommerce / shard

Add new behaviours to Doctrine Mongo ODM Documents
MIT License
4 stars 1 forks source link

Unserialize Nested Abstract Embeds #56

Closed joshystuart closed 10 years ago

joshystuart commented 10 years ago

I'm not sure why this is happening (ie. the root cause), however when I have an EmbedMany with a discriminatorMap, and those classes inherit from an abstract class which also has an embed, I get the following error:

InvalidArgumentException: Association name expected, 'price' is not an association.

See https://github.com/crimsonronin/shard/blob/f95b5b2a67c7e3cc74181f778c2a1dc524b64510/tests/Zoop/Shard/Test/Serializer/TestAsset/Document/Order/Order.php#L35

Adding the following to Unserializer fixes the issue:

} elseif(isset($mapping['targetDocument']) && class_exists($mapping['targetDocument'])) {
    $targetClass = $mapping['targetDocument'];
} else {

Not sure if this is just a bandaid, or the proper fix. Any suggestions @superdweebie?

superdweebie commented 10 years ago

Yep, that's fine. I was trying to use the metadata methods defined in doctrine-common where I could rather than directly touching the metadata array. However, it doesn't seem to work all the time. The addition is good, and means that the else can be deleted, because execution will never get there: https://github.com/crimsonronin/shard/blob/f95b5b2a67c7e3cc74181f778c2a1dc524b64510/lib/Zoop/Shard/Serializer/Unserializer.php#L237