original_string: public function related($relation, $conditions = array())
  	{
  		if (is_array($relation))
  		{
  			foreach ($relation as $k_r => $v_r)
  			{
  				is_array($v_r) ? $this->related($k_r, $v_r) : $this->related($v_r);
  			}
  			return $this;
  		}
  
  		if (strpos($relation, '.'))
  		{
  			$rels = explode('.', $relation);
  			$model = $this->model;
  			foreach ($rels as $r)
  			{
  				$rel = call_user_func(array($model, 'relations'), $r);
  				if (empty($rel))
  				{
  					throw new \UnexpectedValueException('Relation "'.$r.'" was not found in the model "'.$model.'".');
  				}
  				$model = $rel->model_to;
  			}
  		}
  		else
  		{
  			$rel = call_user_func(array($this->model, 'relations'), $relation);
  			if (empty($rel))
  			{
  				throw new \UnexpectedValueException('Relation "'.$relation.'" was not found in the model.');
  			}
  		}
  
  		$this->relations[$relation] = array($rel, $conditions);
  
  		if ( ! empty($conditions['related']))
  		{
  			$conditions['related'] = (array) $conditions['related'];
  			foreach ($conditions['related'] as $k_r => $v_r)
  			{
  				is_array($v_r) ? $this->related($relation.'.'.$k_r, $v_r) : $this->related($relation.'.'.$v_r);
  			}
  
  			unset($conditions['related']);
  		}
  
  		return $this;
  	}
code: public function related($relation, $conditions = array())
  	{
  		if (is_array($relation))
  		{
  			foreach ($relation as $k_r => $v_r)
  			{
  				is_array($v_r) ? $this->related($k_r, $v_r) : $this->related($v_r);
  			}
  			return $this;
  		}
  
  		if (strpos($relation, '.'))
  		{
  			$rels = explode('.', $relation);
  			$model = $this->model;
  			foreach ($rels as $r)
  			{
  				$rel = call_user_func(array($model, 'relations'), $r);
  				if (empty($rel))
  				{
  					throw new \UnexpectedValueException('Relation "'.$r.'" was not found in the model "'.$model.'".');
  				}
  				$model = $rel->model_to;
  			}
  		}
  		else
  		{
  			$rel = call_user_func(array($this->model, 'relations'), $relation);
  			if (empty($rel))
  			{
  				throw new \UnexpectedValueException('Relation "'.$relation.'" was not found in the model.');
  			}
  		}
  
  		$this->relations[$relation] = array($rel, $conditions);
  
  		if ( ! empty($conditions['related']))
  		{
  			$conditions['related'] = (array) $conditions['related'];
  			foreach ($conditions['related'] as $k_r => $v_r)
  			{
  				is_array($v_r) ? $this->related($relation.'.'.$k_r, $v_r) : $this->related($relation.'.'.$v_r);
  			}
  
  			unset($conditions['related']);
  		}
  
  		return $this;
  	}
code_tokens: public function related ( $ relation , $ conditions = array ( ) ) { if ( is_array ( $ relation ) ) { foreach ( $ relation as $ k_r => $ v_r ) { is_array ( $ v_r ) ? $ this -> related ( $ k_r , $ v_r ) : $ this -> related ( $ v_r ) ; } return $ this ; } if ( strpos ( $ relation , '.' ) ) { $ rels = explode ( '.' , $ relation ) ; $ model = $ this -> model ; foreach ( $ rels as $ r ) { $ rel = call_user_func ( array ( $ model , 'relations' ) , $ r ) ; if ( empty ( $ rel ) ) { throw new \ UnexpectedValueException ( 'Relation "' . $ r . '" was not found in the model "' . $ model . '".' ) ; } $ model = $ rel -> model_to ; } } else { $ rel = call_user_func ( array ( $ this -> model , 'relations' ) , $ relation ) ; if ( empty ( $ rel ) ) { throw new \ UnexpectedValueException ( 'Relation "' . $ relation . '" was not found in the model.' ) ; } } $ this -> relations [ $ relation ] = array ( $ rel , $ conditions ) ; if ( ! empty ( $ conditions [ 'related' ] ) ) { $ conditions [ 'related' ] = ( array ) $ conditions [ 'related' ] ; foreach ( $ conditions [ 'related' ] as $ k_r => $ v_r ) { is_array ( $ v_r ) ? $ this -> related ( $ relation . '.' . $ k_r , $ v_r ) : $ this -> related ( $ relation . '.' . $ v_r ) ; } unset ( $ conditions [ 'related' ] ) ; } return $ this ; }
docstring: Set a relation to include
  
  @param   string  $relation
  @param   array   $conditions    Optionally
  
  @throws \UnexpectedValueException Relation was not found in the model
  
  @return  $this
docstring_tokens: Set a relation to include