/** * @param RelationshipInterface $relationship * @param $record */ protected function hydrateLatestTagsRelationship(RelationshipInterface $relationship, $record) { $record->tag_ids = $relationship->getIdentifiers()->getIds(); }
/** * @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; }
/** * Sync a resource has-many relationship * * @param $resourceKey * @param RelationshipInterface $relationship * @param Model $model * @return bool */ protected function syncHasMany($resourceKey, RelationshipInterface $relationship, Model $model) { $relation = $this->getRelation($resourceKey, $model); if (!$relation instanceof BelongsToMany) { return false; } $relation->sync($relationship->getIdentifiers()->getIds()); return true; }