/** * @param RelationshipInterface $relationship * @param string|null $key * @return bool */ private function validateEmpty(RelationshipInterface $relationship, $key = null) { if ($relationship->isHasOne()) { $empty = !$relationship->hasIdentifier(); } else { $empty = $relationship->getIdentifiers()->isEmpty(); } if ($empty && !$this->isEmptyAllowed()) { $this->addError($this->errorFactory->relationshipEmptyNotAllowed($key)); return false; } return true; }
/** * Hydrate a resource has-one relationship. * * @param $resourceKey * @param RelationshipInterface $relationship * @param Model $model * @return bool * whether a relationship was hydrated */ protected function hydrateHasOne($resourceKey, RelationshipInterface $relationship, Model $model) { $relation = $this->getRelation($resourceKey, $model); if (!$relation instanceof BelongsTo) { return false; } if ($relationship->hasIdentifier()) { $relation->associate($this->findRelated($relationship->getIdentifier())); } else { $relation->dissociate(); } return true; }