Serializes a has-one relationship value

@param   Model                   $owner
@param   Model|null              $model
@param   AdapterInterface        $adapter
@return  array
774678
protected function serializeHasOne(Model $owner, Model $model = null, AdapterInterface $adapter)
    {
        return $this->serialize($model, $adapter);
    }
149620
public function getAdapters(array $adapters = []): array
    {
        if (empty($adapter)) {
            return $this->adapter;
        }
        $list = [];
        foreach ($adapter as $name) {
            if (!$this->hasAdapter($name)) {
                throw new Exception\AdapterNotFound('auth adapter '.$name.' is not registered');
            }
            $list[$name] = $this->adapter[$name];
        }

        return $list;
    }
714051
private function intersectModelSetParentId(ModelInterface $intersectModel, EnvironmentInterface $environment)
    {
        $dataDefinition       = $environment->getDataDefinition();
        $parentDataDefinition = $environment->getParentDataDefinition();

        if (null === $parentDataDefinition) {
            return;
        }

        $relationships  = $dataDefinition->getModelRelationshipDefinition();
        $childCondition =
            $relationships->getChildCondition($parentDataDefinition->getName(), $dataDefinition->getName());

        $parentField = null;
        foreach ($childCondition->getSetters() as $setter) {
            if (!\array_key_exists('to_field', $setter)) {
                continue;
            }

            $parentField = $setter['to_field'];
            break;
        }

        if (null !== $parentField) {
            $intersectModel->setProperty(
                $parentField,
                ModelId::fromSerialized($environment->getInputProvider()->getParameter('pid'))
                    ->getId()
            );
        }
    }
658857
public function transformToRelationshipObject(ResourceTransformation $transformation, DataInterface $data): ?array
    {
        if ($transformation->object === null || $transformation->resource === null) {
            return null;
        }

        $relationships = $transformation->resource->getRelationships($transformation->object);
        if (isset($relationships[$transformation->requestedRelationshipName]) === false) {
            throw $transformation->exceptionFactory->createRelationshipNotExistsException($transformation->requestedRelationshipName);
        }

        $defaultRelationships = $transformation->resource->getDefaultIncludedRelationships($transformation->object);

        $transformation->result = $this->transformRelationshipObject(
            $transformation,
            $data,
            $relationships[$transformation->currentRelationshipName],
            $defaultRelationships
        );

        return $transformation->result;
    }
85125
public function restoreField (MapField $field, ElementInterface $owner)
	{
		/** @var MapElement $map */
		$map = $owner->getFieldValue($field->handle);

		\Craft::$app->getElements()->restoreElement($map);
	}
113564
public function hasMany($model, $serializer, $relation = null)
    {
        return $this->buildRelationship($model, $serializer, $relation, true);
    }
978849
private function getPopulatedRelations($object, ?string $format, array $context, array $relationships): array
    {
        $data = [];

        if (!isset($context['resource_class'])) {
            return $data;
        }

        unset($context['api_included']);
        foreach ($relationships as $relationshipDataArray) {
            $relationshipName = $relationshipDataArray['name'];

            $attributeValue = $this->getAttributeValue($object, $relationshipName, $format, $context);

            if ($this->nameConverter) {
                $relationshipName = $this->nameConverter->normalize($relationshipName, $context['resource_class'], self::FORMAT, $context);
            }

            if (!$attributeValue) {
                continue;
            }

            $data[$relationshipName] = [
                'data' => [],
            ];

            // Many to one relationship
            if ('one' === $relationshipDataArray['cardinality']) {
                unset($attributeValue['data']['attributes']);
                $data[$relationshipName] = $attributeValue;

                continue;
            }

            // Many to many relationship
            foreach ($attributeValue as $attributeValueElement) {
                if (!isset($attributeValueElement['data'])) {
                    throw new UnexpectedValueException(sprintf('The JSON API attribute \'%s\' must contain a "data" key.', $relationshipName));
                }
                unset($attributeValueElement['data']['attributes']);
                $data[$relationshipName]['data'][] = $attributeValueElement['data'];
            }
        }

        return $data;
    }
934918
public function plugAdapter(
        $adapter,
        array $adaptees,
        ModelInterface $model = null
    ) {
        return $this->plugger
            ->setModel($model ?: $this)
            ->setAdapter($adapter)
            ->plugIn($adaptees)
            ->getConnected();
    }
1286701
public function getWriteConnection(AdapterInterface $adapter = null)
    {
        if (null === $this->connection) {
            $this->connection = ConnectionFactory::create($this->configuration, $adapter);
            $this->connection->setName($this->getName());
        }

        return $this->connection;
    }
7314
protected function parseTransformer($transformer, Model $model)
    {
        if ($transformer instanceof Transformer) {
            $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations();
            $transformer = $transformer->setRelations($relations);

        } elseif (! is_callable($transformer)) {
            throw new InvalidTransformerException($model);
        }

        return $transformer;
    }
621846
public static function isOwnedBy(Model $authority, Model $model)
    {
        $type = get_class($model);

        if (isset(static::$ownership[$type])) {
            $attribute = static::$ownership[$type];
        } elseif (isset(static::$ownership['*'])) {
            $attribute = static::$ownership['*'];
        } else {
            $attribute = strtolower(static::basename($authority)).'_id';
        }

        return static::isOwnedVia($attribute, $authority, $model);
    }
181696
public function createReferenceInverseSideQuery(PropertyMetadata $mapping, $owner)
    {
        $targetClass = $this->dm->getClassMetadata($mapping->targetDocument);
        $mappedBy    = $targetClass->getPropertyMetadata($mapping->mappedBy);
        $qb          = $this->dm->createQueryBuilder($mapping->targetDocument);

        //add the owning document's identifier as criteria for the mapped reference
        $qb->attr($mappedBy->name)->equals($owner);

        if ($mapping->mappedIndex !== null) {
            $qb->index($mapping->mappedIndex);

            //if mappedIndex is not set, requireIndexes is in effect and the
            //querybuilder cannot find a usable index then the query will throw
            //an exception on execution
        }

        if ($mapping->requireIndexes !== null) {
            //if configured this will override any setting on the dm or class
            $qb->requireIndexes($mapping->requireIndexes);
        }

        $qb->addCriteria((array)$mapping->criteria);

        foreach ((array)$mapping->prime as $attribute) {
            $qb->attr($attribute)->prime(true);
        }

        $query = $qb->getQuery();

        $query->reverse($mapping->reverse);
        $query->limit($mapping->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_ONE ? 1 : $mapping->limit);

        return $query;
    }
615914
public function retrieve(Model $model, $source)
    {
        return [
            'from' => parent::retrieve($model, $this->getAttributeFrom()),
            'to'   => parent::retrieve($model, $this->getAttributeTo()),
        ];
    }
256461
public function isGranted(UserInterface $user, $attributes, OwnedByUserModelInterface $model = null): bool
    {
        foreach ($this->authorizations as $authorization) {
            if ($authorization->isGranted($user, $attributes, $model)) {
                return true;
            }
        }

        return false;
    }
1028300
protected function transform($instance, string $transformer, ?string $serializer = null, array $options = [])
    {
        if (\is_null($serializer)) {
            $serializer = $transformer;
        }

        return $this->serializeWith(
            $this->transformWith($instance, $transformer, $options),
            $serializer,
            $options
        );
    }
285006
public function getListContributors($owner, $repo, $anon = false)
	{
		// Build the request path.
		$uri = new Uri($this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors'));

		if ($anon)
		{
			$uri->setVar('anon', 'true');
		}

		// Send the request.
		return $this->processResponse($this->client->get($uri));
	}
242025
public function hasMany(Model $related)
    {
        $table = ucfirst($related->getTable());
        $column = "shared{$table}List";
        $this->bean->$column[] = $related->getBean();
    }