Get referenced row(s) by name. Suffix "List" gets many rows

@param string $name
@param string|array|null $where
@param array $params
@return Result
438652
function referenced( $name, $where = null, $params = array() ) {

        $result = $this->db->createResult( $this, $name );

        if ( $where !== null ) {

            if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 2 );
            $result = $result->where( $where, $params );

        }

        return $result;

    }
492852
public function paginateFindWhere(Where $where, $item_per_page, $page = 1, $suffix = '')
    {
        $projection = $this->createProjection();

        return $this->paginateQuery(
            $this->getFindWhereSql($where, $projection, $suffix),
            $where->getValues(),
            $this->countWhere($where),
            $item_per_page,
            $page,
            $projection
        );
    }
321755
public function remove($where, $params = array())
    {
        if (empty($where)) {
            return false;
        }

        $query = "DELETE FROM {$this->getLibName()} WHERE {$where}";
        $statement = $this->pdo->prepare($query);
        $statement->execute($params);
        $this->lastSql = $query;
        return $statement->rowCount();
    }
1099322
public function sqlExists(
		$from,
		$where = null,
		array $params = []
	) {
		$sql = $this->queryBuilder->buildExists($from, $where);
		$query = $this->database->prepare($sql);
		$query->execute($params);
		$this->addQuery($query->queryString, $params);
		return (boolean)$query->fetchColumn();
	}
350467
protected function getIndex(string $name = null): array
    {
        return self::query($this->db->createIndex($name ? $name : $this->tableName));
    }
34260
protected function findIterator( $where = null, $order = null )
    {
        $names = $this->queryNames( $where );

        if ( null !== $order && '' !== $order )
        {
            sort( $names, SORT_NATURAL );

            if ( ! $order )
            {
                $names = array_reverse( $names );
            }
        }

        return new StructureList( $this, $names );
    }
1322415
private static function getReferParams($name)
    {
        static $params = null;

        if (is_null($params)) {
            if (isset($_SERVER['HTTP_REFERER'])) {
                $args = parse_url($_SERVER['HTTP_REFERER']);
                parse_str($args['query'], $params);
            }
        }
        return isset($params[$name]) ? $params[$name] : null;
    }
1178579
public function findByWhereFilter($name, $filter, $orderColumn = null, $orderType = NULL) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $query = "SELECT * FROM `" . $mapper->getTable() . "` ";
        $query .= "WHERE 1 ";
        if (!is_null($filter)) {
            $query .= "AND " . $filter;
        }

        if (!is_null($orderColumn)) {
            $query .= "ORDER BY `$orderColumn` ";
            if (!is_null($orderType)) {
                $query .= "$orderType";
            } else {
                $query .= "ASC ";
            }
        }

        $result = $this->getDataSource()->query($query);

        if ($result) {
            $collection = new Collection($mapper->getClass(), $result, $mapper);
        } else {
            $collection = new Collection($mapper->getClass(), array(), $mapper);
        }

        return $collection;
    }
289478
public function executeFetchAll(
        $query = null,
        $params = []
    ) {

        $this->execute($query, $params);
        return $this->fetchAll();
    }
69542
public function getFromWhere($from, $where=NULL, $where_values=array(), $order=NULL, $limit=NULL, $offset=NULL){
        $res= FALSE;
        try{
            //Armo partes de la consulta
            if($order != NULL){$order= " ORDER BY " . $order;}
            if($limit != NULL){
                $limit= " LIMIT " . $limit;
                if($offset != NULL){$limit.= ' OFFSET ' . $offset;}
            }
            //Armo y preparo la consulta
            $query= $this->prepareSelect($this->select, $from, $where, '', '', $order, $limit);
            //Ejecuto la consulta
            $query->execute($where_values);
            //Controlo que este todo bien
            if($this->isOk($query)){
                $res= $query;
            }
            //Limpio las variables del AR
            $this->cleanVars();
        } catch (\PDOException $e) {
            $this->cleanVars();
            throw $e;
        }
        return $res;
    }
305869
protected function queryNames( $where = null )
    {
        $result     = array();
        $lock       = static::getLockData();
        $enabled    = $this->getEnabledList();

        if ( $where )
        {
            if ( is_scalar( $where ) )
            {
                $where = array(
                    'category' => (string) $where,
                );
            }
            else
            {
                $where = (array) $where;
            }
        }
        else
        {
            $where = array();
        }

        if ( empty( $where['category'] ) )
        {
            $where['category'] = null;
        }
        else
        {
            $where['category'] = (array) $where['category'];
        }

        if ( empty( $where['contains'] ) )
        {
            $where['contains'] = null;
        }

        if ( ! isset( $where['installed'] ) || '' === $where['installed'] )
        {
            $where['installed'] = null;
        }
        else
        {
            $where['installed'] = (bool) $where['installed'];
        }

        if ( ! isset( $where['author'] ) || '' === $where['author'] )
        {
            $where['author'] = null;
        }
        else
        {
            $where['author'] = (string) $where['author'];
        }

        if ( null === $where['author'] &&
             ( ! isset( $where['installed'] ) || ! $where['installed'] ) )
        {
            $total    = 0;
            $packages = $this->queryJson( sprintf(
                static::PACKAGE_LIST_URL,
                urlencode( $where['contains'] )
            ) );

            while ( ! empty( $packages['results'] ) )
            {
                foreach ( $packages['results'] as $package )
                {
                    if ( $enabled->isEnabled( $package['name'],
                                              $where['category'] ) )
                    {
                        $result[$package['name']] = $package['name'];
                    }

                    $total++;
                }

                if ( isset( $packages['total'] ) &&
                     $total >= $packages['total'] )
                {
                    break;
                }

                if ( empty( $packages['next'] ) )
                {
                    $packages = array();
                }
                else
                {
                    $packages = $this->queryJson( $packages['next'] );
                }
            }
        }

        if ( ! empty( $lock['packages'] ) )
        {
            foreach ( $lock['packages'] as $package )
            {
                if ( isset( $package['name'] ) &&
                     isset( $package['type'] ) &&
                     preg_match( Structure::VALID_TYPES, $package['type'] ) &&
                     $enabled->isEnabled( $package['name'], $where['category'] ) && (
                         ! $where['contains'] || $this->contains(
                             $where['contains'],
                             $package['name'],
                             isset( $package['description'] ) ? $package['description'] : null,
                             isset( $package['keywords'] ) ? (array) $package['keywords'] : array()
                         )
                     ) )
                {
                    if ( ! isset( $where['installed'] ) || $where['installed'] )
                    {
                        if ( null === $where['author'] )
                        {
                            $result[$package['name']] = $package['name'];
                        }
                        else if ( empty( $package['authors'] ) )
                        {
                            unset( $result[$package['name']] );
                        }
                        else
                        {
                            foreach ( (array) $package['authors'] as $author )
                            {
                                if ( ! empty( $author['email'] ) && $author['email'] == $where['author'] )
                                {
                                    $result[$package['name']] = $package['name'];
                                    continue 2;
                                }
                            }

                            unset( $result[$package['name']] );
                        }
                    }
                    else if ( isset( $result[$package['name']] ) )
                    {
                        unset( $result[$package['name']] );
                    }
                }
            }
        }

        return array_values( $result );
    }
958982
function where( $condition, $params = array() ) {

        $clone = clone $this;

        // conditions in key-value array
        if ( is_array( $condition ) ) {

            foreach ( $condition as $c => $params ) {

                $clone = $clone->where( $c, $params );

            }

            return $clone;

        }

        // shortcut for basic "column is (in) value"
        if ( preg_match( '/^[a-z0-9_.`"]+$/i', $condition ) ) {

            $clone->where[] = $clone->db->is( $condition, $params );

            return $clone;

        }

        if ( !is_array( $params ) ) {

            $params = func_get_args();
            array_shift( $params );

        }

        $clone->where[] = $condition;
        $clone->whereParams = array_merge( $clone->whereParams, $params );

        return $clone;

    }
177434
public function getRow($sql, $params = [])
    {
        if ($sql instanceof Criteria\Criteria) return $this->getRow($sql->toSQL(), $sql->getParams());

        $sth = $this->query($sql, $params, Database::TARGET_SLAVE);
        $row = $sth->fetch(Connection::FETCH_OBJ);
        $sth->closeCursor();
        return $row;
    }
346511
function getReference( $table, $name ) {

        if ( isset( $this->references[ $table ][ $name ] ) ) {

            return $this->references[ $table ][ $name ];

        }

        return $name . '_id';

    }
759298
public function query($query_with_placeholders, $named_parameters = []) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_QUERY, '', $named_parameters, $query_with_placeholders), $named_parameters);
            try {
                $stmt = $this->prepareStatement($query_with_placeholders, $named_parameters);
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $query_with_placeholders, $named_parameters));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            Event::dispatch(EventData::forAfter(Event::AFTER_QUERY, null, $named_parameters, $query_with_placeholders, $stmt->rowCount()));

            return $this->fetch($stmt);
        }
394097
public function addWhere($where, $params = [], $operator = 'AND')
    {
        if ($where instanceof Criteria) {
            return $this->addCriteria($where);
        }
        if (null === $where) {
            return $this;
        }
        if (isset($this->query['where']) && !empty($this->query['where'])) {
            $operator = strtoupper($operator);
            $where = "({$this->query['where']}) {$operator} ({$where})";
        }
        $this->query['where'] = $where;
        $this->addParams($params);
        return $this;
    }
234322
public function getReferencedDocumentList($name)
    {
        $referenceList = $this->get($name);
        if (null === $referenceList) {
            return null;
        }

        if (!isset($referenceList[0])) {
            throw new Exception('List of references not found');
        }

        // build list of referenced collections and ids
        $documentIdList = array();
        foreach ($referenceList as $reference) {
            if (empty($reference['$ref']) || empty($reference['$id'])) {
                throw new Exception(sprintf(
                    'Invalid reference in list for document %s in field %s',
                    $this->getId(),
                    $name
                ));
            }

            $documentIdList[$reference['$ref']][] = $reference['$id'];
        }

        // get list
        $documentList = array();
        $database = $this->collection->getDatabase();
        foreach ($documentIdList as $collectionName => $documentIdList) {
            $documentList += $database->getCollection($collectionName)->find()->byIdList($documentIdList)->findAll();
        }

        return $documentList;
    }