public static function find($id, $limit = -1, string $table = "", bool $setRelations = true)
    {
        $query = new QueryBuilder(self::$_connection);
        $model = new static();

        $query->select("*");

        if($table === "") {
            $query->from($model->getTable());
        } else {
            $query->from($table);
        }

        $query = static::_setWhere($id, $query, $model->_primaryKey);

        if(
            is_int($limit) &&
            $limit < 0
        ) {
            $query->limit(1);
        } else {
            $query->limit($limit);
        }

        $result = $query->execute();
        $return = [];

        foreach($result as $r) {
            if(
                empty($limit) ||
                is_int($limit) && $limit < 0
            ) {
                $model = new static($r, $setRelations);
                if($table !== "") {
                    $model->_table = $table;
                }

                return $model;
            }

            $model = new static($r, $setRelations);
            if($table !== "") {
                $model->_table = $table;
            }

            $return[] = $model;
        }

        return $return;
    }
public static function find($id, $limit = -1, string $table = "", bool $setRelations = true)
    {
        $query = new QueryBuilder(self::$_connection);
        $model = new static();

        $query->select("*");

        if($table === "") {
            $query->from($model->getTable());
        } else {
            $query->from($table);
        }

        $query = static::_setWhere($id, $query, $model->_primaryKey);

        if(
            is_int($limit) &&
            $limit < 0
        ) {
            $query->limit(1);
        } else {
            $query->limit($limit);
        }

        $result = $query->execute();
        $return = [];

        foreach($result as $r) {
            if(
                empty($limit) ||
                is_int($limit) && $limit < 0
            ) {
                $model = new static($r, $setRelations);
                if($table !== "") {
                    $model->_table = $table;
                }

                return $model;
            }

            $model = new static($r, $setRelations);
            if($table !== "") {
                $model->_table = $table;
            }

            $return[] = $model;
        }

        return $return;
    }
public static function find ( $ id , $ limit = - 1 , string $ table = "" , bool $ setRelations = true ) { $ query = new QueryBuilder ( self :: $ _connection ) ; $ model = new static ( ) ; $ query -> select ( "*" ) ; if ( $ table === "" ) { $ query -> from ( $ model -> getTable ( ) ) ; } else { $ query -> from ( $ table ) ; } $ query = static :: _setWhere ( $ id , $ query , $ model -> _primaryKey ) ; if ( is_int ( $ limit ) && $ limit < 0 ) { $ query -> limit ( 1 ) ; } else { $ query -> limit ( $ limit ) ; } $ result = $ query -> execute ( ) ; $ return = [ ] ; foreach ( $ result as $ r ) { if ( empty ( $ limit ) || is_int ( $ limit ) && $ limit < 0 ) { $ model = new static ( $ r , $ setRelations ) ; if ( $ table !== "" ) { $ model -> _table = $ table ; } return $ model ; } $ model = new static ( $ r , $ setRelations ) ; if ( $ table !== "" ) { $ model -> _table = $ table ; } $ return [ ] = $ model ; } return $ return ; }
Finds and returns one or more record from the database.

@param int|string|array $id           Primary key value or `WHERE` clause.
@param int|array        $limit        Amount of records to retrieve from database,
if `-1` (or empty array) an instance of the Model
class will be returned.
@param string           $table        Table that will be used to get the records from.
@param bool             $setRelations Whether relations should be processed or not.

@return Model|Model[] Records from the database.
Finds and returns one or more record from the database .