/** * Gets the metadata for a relationship. * * @param RelationshipMetadata $relMeta The relationship metadata. * @return EntityMetadata */ public function getMetadataForRelationship(RelationshipMetadata $relMeta) { return $this->getMetadataForType($relMeta->getEntityType()); }
/** * {@inheritdoc} */ protected function validateRelationship(RelationshipMetadata $relationship) { if (true === $this->hasAttribute($relationship->getKey())) { throw MetadataException::fieldKeyInUse('relationship', 'attribute', $relationship->getKey(), $this->name); } if (true === $this->hasEmbed($relationship->getKey())) { throw MetadataException::fieldKeyInUse('relationship', 'embed', $relationship->getKey(), $this->name); } }
/** * Sets the entity relationship metadata from the metadata mapping. * * @param Metadata\Interfaces\RelationshipInterface $metadata * @param array $relMapping * @return Metadata\Interfaces\RelationshipInterface * @throws RuntimeException If the related entity type was not found. */ protected function setRelationships(Metadata\Interfaces\RelationshipInterface $metadata, array $relMapping) { foreach ($relMapping as $key => $mapping) { if (!is_array($mapping)) { $mapping = ['type' => null, 'entity' => null]; } if (!isset($mapping['type'])) { $mapping['type'] = null; } if (!isset($mapping['entity'])) { $mapping['entity'] = null; } if (!isset($mapping['search'])) { $mapping['search'] = []; } $relationship = new Metadata\RelationshipMetadata($key, $mapping['type'], $mapping['entity'], $this->isMixin($metadata)); if (isset($mapping['description'])) { $relationship->description = $mapping['description']; } if (isset($mapping['inverse'])) { $relationship->isInverse = true; if (isset($mapping['field'])) { $relationship->inverseField = $mapping['field']; } } $path = $this->getFilePath('model', $mapping['entity']); $relatedEntityMapping = $this->getMapping('model', $mapping['entity'], $path); if (isset($relatedEntityMapping['entity']['polymorphic'])) { $relationship->setPolymorphic(true); $relationship->ownedTypes = $this->getOwnedTypes($mapping['entity']); } if (isset($mapping['search']['store'])) { $relationship->setSearchProperty(true); } if (isset($mapping['save'])) { $relationship->enableSave($mapping['save']); } if (isset($mapping['serialize'])) { $relationship->enableSerialize($mapping['serialize']); } $metadata->addRelationship($relationship); } return $metadata; }