protected function select(
        array $columns = null,
        array $criteria = null,
        array $orderBy = null,
        int $limit = null,
        int $offset = null,
        bool $getRelations = null
    ) {
        // Build the query
        $query = $this->selectQueryBuilder($columns, $criteria, $orderBy, $limit, $offset);

        // Create a new PDO statement from the query builder
        $stmt = $this->store->prepare($query->getQuery());

        // Iterate through the criteria once more
        foreach ($criteria as $column => $criterion) {
            // If the criterion is null
            if ($criterion === null) {
                // Skip as we've already set the where to IS NULL
                continue;
            }

            // If the criterion is an array
            if (\is_array($criterion)) {
                // Iterate through the criterion and bind each value individually
                foreach ($criterion as $index => $criterionItem) {
                    $stmt->bindValue($this->columnParam($column . $index), $criterionItem);
                }

                continue;
            }

            // And bind each value to the column
            $stmt->bindValue($this->columnParam($column), $criterion);
        }

        // Execute the PDO statement
        $stmt->execute();

        // Get all the results from the PDO statement
        $rows    = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $results = [];

        // If the result of the query was a count
        if (isset($rows[0]['COUNT(*)'])) {
            return (int) $rows[0]['COUNT(*)'];
        }

        // Iterate through the rows found
        foreach ($rows as $row) {
            // Create a new model
            /** @var \Valkyrja\ORM\Entity $entity */
            $entity = new $this->entity();
            // Apply the model's contents given the row
            $entity->fromArray($row);

            // If no columns were specified then we can safely get all the relations
            if (null === $columns && $getRelations === true) {
                // Add the model to the final results
                $results[] = $this->getEntityRelations($entity);
            } else {
                // Add the model to the final results
                $results[] = $entity;
            }
        }

        return $results;
    }
protected function select(
        array $columns = null,
        array $criteria = null,
        array $orderBy = null,
        int $limit = null,
        int $offset = null,
        bool $getRelations = null
    ) {
        // Build the query
        $query = $this->selectQueryBuilder($columns, $criteria, $orderBy, $limit, $offset);

        // Create a new PDO statement from the query builder
        $stmt = $this->store->prepare($query->getQuery());

        // Iterate through the criteria once more
        foreach ($criteria as $column => $criterion) {
            // If the criterion is null
            if ($criterion === null) {
                // Skip as we've already set the where to IS NULL
                continue;
            }

            // If the criterion is an array
            if (\is_array($criterion)) {
                // Iterate through the criterion and bind each value individually
                foreach ($criterion as $index => $criterionItem) {
                    $stmt->bindValue($this->columnParam($column . $index), $criterionItem);
                }

                continue;
            }

            // And bind each value to the column
            $stmt->bindValue($this->columnParam($column), $criterion);
        }

        // Execute the PDO statement
        $stmt->execute();

        // Get all the results from the PDO statement
        $rows    = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $results = [];

        // If the result of the query was a count
        if (isset($rows[0]['COUNT(*)'])) {
            return (int) $rows[0]['COUNT(*)'];
        }

        // Iterate through the rows found
        foreach ($rows as $row) {
            // Create a new model
            /** @var \Valkyrja\ORM\Entity $entity */
            $entity = new $this->entity();
            // Apply the model's contents given the row
            $entity->fromArray($row);

            // If no columns were specified then we can safely get all the relations
            if (null === $columns && $getRelations === true) {
                // Add the model to the final results
                $results[] = $this->getEntityRelations($entity);
            } else {
                // Add the model to the final results
                $results[] = $entity;
            }
        }

        return $results;
    }
protected function select ( array $ columns = null , array $ criteria = null , array $ orderBy = null , int $ limit = null , int $ offset = null , bool $ getRelations = null ) { // Build the query $ query = $ this -> selectQueryBuilder ( $ columns , $ criteria , $ orderBy , $ limit , $ offset ) ; // Create a new PDO statement from the query builder $ stmt = $ this -> store -> prepare ( $ query -> getQuery ( ) ) ; // Iterate through the criteria once more foreach ( $ criteria as $ column => $ criterion ) { // If the criterion is null if ( $ criterion === null ) { // Skip as we've already set the where to IS NULL continue ; } // If the criterion is an array if ( \ is_array ( $ criterion ) ) { // Iterate through the criterion and bind each value individually foreach ( $ criterion as $ index => $ criterionItem ) { $ stmt -> bindValue ( $ this -> columnParam ( $ column . $ index ) , $ criterionItem ) ; } continue ; } // And bind each value to the column $ stmt -> bindValue ( $ this -> columnParam ( $ column ) , $ criterion ) ; } // Execute the PDO statement $ stmt -> execute ( ) ; // Get all the results from the PDO statement $ rows = $ stmt -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ results = [ ] ; // If the result of the query was a count if ( isset ( $ rows [ 0 ] [ 'COUNT(*)' ] ) ) { return ( int ) $ rows [ 0 ] [ 'COUNT(*)' ] ; } // Iterate through the rows found foreach ( $ rows as $ row ) { // Create a new model /** @var \Valkyrja\ORM\Entity $entity */ $ entity = new $ this -> entity ( ) ; // Apply the model's contents given the row $ entity -> fromArray ( $ row ) ; // If no columns were specified then we can safely get all the relations if ( null === $ columns && $ getRelations === true ) { // Add the model to the final results $ results [ ] = $ this -> getEntityRelations ( $ entity ) ; } else { // Add the model to the final results $ results [ ] = $ entity ; } } return $ results ; }
Select entities by given criteria.

<code>
$this->select(
[
'column',
'column2',
],
[
'column'  => 'value',
'column2' => 'value2',
],
[
'column'
'column2' => OrderBy::ASC,
'column3' => OrderBy::DESC,
],
1,
1
)
</code>

@param array|null $columns
@param array|null $criteria
@param array|null $orderBy
@param int|null   $limit
@param int|null   $offset
@param bool|null  $getRelations

@throws InvalidArgumentException

@return \Valkyrja\ORM\Entity[]|int
Select entities by given criteria .