diff --git a/Configuration/Metadata/ClassMetadata.php b/Configuration/Metadata/ClassMetadata.php index 89be6ea..5b6cc71 100644 --- a/Configuration/Metadata/ClassMetadata.php +++ b/Configuration/Metadata/ClassMetadata.php @@ -16,6 +16,7 @@ use Mango\Bundle\JsonApiBundle\Configuration\Relationship; use Mango\Bundle\JsonApiBundle\Configuration\Resource; use Metadata\MergeableClassMetadata; +use Metadata\MergeableInterface; /** * @author Steffen Brem @@ -104,6 +105,25 @@ public function addRelationship($relationship) $this->relationships->add($relationship); } + /** + * {@inheritDoc} + */ + public function merge(MergeableInterface $object) + { + if (!$object instanceof self) { + throw new \InvalidArgumentException(sprintf('Object must be an instance of %s.', __CLASS__)); + } + + parent::merge($object); + + $this->resource = $object->getResource(); + $this->idField = $object->getIdField(); + + foreach ($object->getRelationships() as $relationship) { + $this->addRelationship($relationship); + } + } + /** * {@inheritdoc} */