public function applyRelationship(Entity $owner, $fieldKey, EntityInterface $related)
    {
        $meta = $this->em->getMetadataForType($owner->getType());
        if (false === $meta->hasRelationship($fieldKey)) {
            throw new InvalidArgumentException('The resource "%s" does not contain relationship field "%s"', $owner->getType(), $fieldKey);
        }
        $relMeta = $meta->getRelationship($fieldKey);
        $this->validateResourceTypes($relMeta->getEntityType(), $related->getType());

        $relationship = $this->createRelationship($fieldKey, $relMeta->getType());
        $relationship->pushData($related);
        $owner->addRelationship($relationship);
        return $this;
    }
public function applyRelationship(Entity $owner, $fieldKey, EntityInterface $related)
    {
        $meta = $this->em->getMetadataForType($owner->getType());
        if (false === $meta->hasRelationship($fieldKey)) {
            throw new InvalidArgumentException('The resource "%s" does not contain relationship field "%s"', $owner->getType(), $fieldKey);
        }
        $relMeta = $meta->getRelationship($fieldKey);
        $this->validateResourceTypes($relMeta->getEntityType(), $related->getType());

        $relationship = $this->createRelationship($fieldKey, $relMeta->getType());
        $relationship->pushData($related);
        $owner->addRelationship($relationship);
        return $this;
    }
public function applyRelationship ( Entity $ owner , $ fieldKey , EntityInterface $ related ) { $ meta = $ this -> em -> getMetadataForType ( $ owner -> getType ( ) ) ; if ( false === $ meta -> hasRelationship ( $ fieldKey ) ) { throw new InvalidArgumentException ( 'The resource "%s" does not contain relationship field "%s"' , $ owner -> getType ( ) , $ fieldKey ) ; } $ relMeta = $ meta -> getRelationship ( $ fieldKey ) ; $ this -> validateResourceTypes ( $ relMeta -> getEntityType ( ) , $ related -> getType ( ) ) ; $ relationship = $ this -> createRelationship ( $ fieldKey , $ relMeta -> getType ( ) ) ; $ relationship -> pushData ( $ related ) ; $ owner -> addRelationship ( $ relationship ) ; return $ this ; }
Applies a single relationship to an owning resource via a related resource object.

@param   Entity              $owner          The owning entity to apply the relationship to.
@param   string              $fieldKey       The relationship field key.
@param   EntityInterface     $related        The related EntityInterface to add to the owner.
@throws  InvalidArgumentException            If the relationship field key does not exist on the owner.
@return  self
Applies a single relationship to an owning resource via a related resource object .