/** * {@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); } }
/** * Loads a has-many model collection. * * @param RelationshipMetadata $relMeta * @param array|null $references * @return Collections\Collection */ public function createCollection(RelationshipMetadata $relMeta, array $references = null) { $metadata = $this->getMetadataForType($relMeta->getEntityType()); if (empty($references)) { $references = []; } if (false === $this->isSequentialArray($references)) { throw StoreException::badRequest(sprintf('Improper has-many data detected for relationship "%s" - a sequential array is required.', $relMeta->getKey())); } $models = []; foreach ($references as $reference) { $models[] = $this->loadProxyModel($reference['type'], $reference['id']); } return new Collections\Collection($metadata, $this, $models, count($models)); }