protected function _find($id, $options = [])
    {
        $defaults = [
            'query'        => [],
            'fetchOptions' => []
        ];
        $options += $defaults;

        $fetchOptions = $options['fetchOptions'];
        unset($options['fetchOptions']);

        if ($this->link() !== static::LINK_KEY) {
            throw new ORMException("This relation is not based on a foreign key.");
        }
        $to = $this->to();
        $schema = $to::definition();

        if (!$id) {
            return $to::create([], ['type' => 'set']);
        }

        $ids = is_array($id) ? $id : [$id];
        $key = $schema->key();
        $column = $schema->column($key);

        foreach ($ids as $i => $value) {
            $ids[$i] = $schema->convert('cast', $column['type'], $value, $column);
        }

        if (count($ids) === 1) {
            $ids = reset($ids);
        }
        $conditions = [$this->keys('to') => $ids];
        if ($this->conditions()) {
            $conditions = [
                ':and()' => [
                    [$this->keys('to') => $ids],
                    $this->conditions()
                ]
            ];
        }
        $query = Set::extend($options['query'], ['conditions' => $conditions]);
        return $to::all($query, $fetchOptions);
    }
protected function _find($id, $options = [])
    {
        $defaults = [
            'query'        => [],
            'fetchOptions' => []
        ];
        $options += $defaults;

        $fetchOptions = $options['fetchOptions'];
        unset($options['fetchOptions']);

        if ($this->link() !== static::LINK_KEY) {
            throw new ORMException("This relation is not based on a foreign key.");
        }
        $to = $this->to();
        $schema = $to::definition();

        if (!$id) {
            return $to::create([], ['type' => 'set']);
        }

        $ids = is_array($id) ? $id : [$id];
        $key = $schema->key();
        $column = $schema->column($key);

        foreach ($ids as $i => $value) {
            $ids[$i] = $schema->convert('cast', $column['type'], $value, $column);
        }

        if (count($ids) === 1) {
            $ids = reset($ids);
        }
        $conditions = [$this->keys('to') => $ids];
        if ($this->conditions()) {
            $conditions = [
                ':and()' => [
                    [$this->keys('to') => $ids],
                    $this->conditions()
                ]
            ];
        }
        $query = Set::extend($options['query'], ['conditions' => $conditions]);
        return $to::all($query, $fetchOptions);
    }
protected function _find ( $ id , $ options = [ ] ) { $ defaults = [ 'query' => [ ] , 'fetchOptions' => [ ] ] ; $ options += $ defaults ; $ fetchOptions = $ options [ 'fetchOptions' ] ; unset ( $ options [ 'fetchOptions' ] ) ; if ( $ this -> link ( ) !== static :: LINK_KEY ) { throw new ORMException ( "This relation is not based on a foreign key." ) ; } $ to = $ this -> to ( ) ; $ schema = $ to :: definition ( ) ; if ( ! $ id ) { return $ to :: create ( [ ] , [ 'type' => 'set' ] ) ; } $ ids = is_array ( $ id ) ? $ id : [ $ id ] ; $ key = $ schema -> key ( ) ; $ column = $ schema -> column ( $ key ) ; foreach ( $ ids as $ i => $ value ) { $ ids [ $ i ] = $ schema -> convert ( 'cast' , $ column [ 'type' ] , $ value , $ column ) ; } if ( count ( $ ids ) === 1 ) { $ ids = reset ( $ ids ) ; } $ conditions = [ $ this -> keys ( 'to' ) => $ ids ] ; if ( $ this -> conditions ( ) ) { $ conditions = [ ':and()' => [ [ $ this -> keys ( 'to' ) => $ ids ] , $ this -> conditions ( ) ] ] ; } $ query = Set :: extend ( $ options [ 'query' ] , [ 'conditions' => $ conditions ] ) ; return $ to :: all ( $ query , $ fetchOptions ) ; }
Gets all entities attached to a collection en entities.

@param  mixed  $id An id or an array of ids.
@return object     A collection of items matching the id/ids.
Gets all entities attached to a collection en entities .