public function build(ModelInterface $model, $relation)
    {
        list($current, $further) = $this->splitRelationName($relation);
        $definition = $this->fetchDefinition($model, $current);

        switch ($definition->type()) {
            case self::RELATION_ONE:
                $instance = new OneRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_MANY:
                $instance = new ManyRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_ONE_TROUGH:
                $instance = new OneTroughRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_MANY_TROUGH:
                $instance = new ManyTroughRelation($this->storage, $definition, $this->bag, $this);
                break;
            default:
                throw new RelationException(sprintf('Invalid relation type "%s" for "%s"', $definition->type(), $definition->entity()));
        }

        if ($further) {
            $instance->with($further);
        }

        return $instance;
    }
public function build(ModelInterface $model, $relation)
    {
        list($current, $further) = $this->splitRelationName($relation);
        $definition = $this->fetchDefinition($model, $current);

        switch ($definition->type()) {
            case self::RELATION_ONE:
                $instance = new OneRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_MANY:
                $instance = new ManyRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_ONE_TROUGH:
                $instance = new OneTroughRelation($this->storage, $definition, $this->bag, $this);
                break;
            case self::RELATION_MANY_TROUGH:
                $instance = new ManyTroughRelation($this->storage, $definition, $this->bag, $this);
                break;
            default:
                throw new RelationException(sprintf('Invalid relation type "%s" for "%s"', $definition->type(), $definition->entity()));
        }

        if ($further) {
            $instance->with($further);
        }

        return $instance;
    }
public function build ( ModelInterface $ model , $ relation ) { list ( $ current , $ further ) = $ this -> splitRelationName ( $ relation ) ; $ definition = $ this -> fetchDefinition ( $ model , $ current ) ; switch ( $ definition -> type ( ) ) { case self :: RELATION_ONE : $ instance = new OneRelation ( $ this -> storage , $ definition , $ this -> bag , $ this ) ; break ; case self :: RELATION_MANY : $ instance = new ManyRelation ( $ this -> storage , $ definition , $ this -> bag , $ this ) ; break ; case self :: RELATION_ONE_TROUGH : $ instance = new OneTroughRelation ( $ this -> storage , $ definition , $ this -> bag , $ this ) ; break ; case self :: RELATION_MANY_TROUGH : $ instance = new ManyTroughRelation ( $ this -> storage , $ definition , $ this -> bag , $ this ) ; break ; default : throw new RelationException ( sprintf ( 'Invalid relation type "%s" for "%s"' , $ definition -> type ( ) , $ definition -> entity ( ) ) ) ; } if ( $ further ) { $ instance -> with ( $ further ) ; } return $ instance ; }
Sets model and its relation

@param ModelInterface $model
@param string         $relation

@return RelationInterface
@throws RelationException
Sets model and its relation