public function tryLoad(Model $m, $id)
    {
        if (!$m->id_field) {
            throw new Exception(['Unable to load field by "id" when Model->id_field is not defined.', 'id'=>$id]);
        }

        $load = $m->action('select');
        $load->where($m->getField($m->id_field), $id);
        $load->limit(1);

        // execute action
        try {
            $data = $this->typecastLoadRow($m, $load->getRow());
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to load due to query error',
                'query'      => $load->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        if (!$data) {
            return;
        }

        if (!isset($data[$m->id_field]) || is_null($data[$m->id_field])) {
            throw new Exception([
                'Model uses "id_field" but it wasn\'t available in the database',
                'model'       => $m,
                'id_field'    => $m->id_field,
                'id'          => $id,
                'data'        => $data,
            ]);
        }

        $m->id = $data[$m->id_field];

        return $data;
    }
public function tryLoad(Model $m, $id)
    {
        if (!$m->id_field) {
            throw new Exception(['Unable to load field by "id" when Model->id_field is not defined.', 'id'=>$id]);
        }

        $load = $m->action('select');
        $load->where($m->getField($m->id_field), $id);
        $load->limit(1);

        // execute action
        try {
            $data = $this->typecastLoadRow($m, $load->getRow());
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to load due to query error',
                'query'      => $load->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        if (!$data) {
            return;
        }

        if (!isset($data[$m->id_field]) || is_null($data[$m->id_field])) {
            throw new Exception([
                'Model uses "id_field" but it wasn\'t available in the database',
                'model'       => $m,
                'id_field'    => $m->id_field,
                'id'          => $id,
                'data'        => $data,
            ]);
        }

        $m->id = $data[$m->id_field];

        return $data;
    }
public function tryLoad ( Model $ m , $ id ) { if ( ! $ m -> id_field ) { throw new Exception ( [ 'Unable to load field by "id" when Model->id_field is not defined.' , 'id' => $ id ] ) ; } $ load = $ m -> action ( 'select' ) ; $ load -> where ( $ m -> getField ( $ m -> id_field ) , $ id ) ; $ load -> limit ( 1 ) ; // execute action try { $ data = $ this -> typecastLoadRow ( $ m , $ load -> getRow ( ) ) ; } catch ( \ PDOException $ e ) { throw new Exception ( [ 'Unable to load due to query error' , 'query' => $ load -> getDebugQuery ( false ) , 'model' => $ m , 'conditions' => $ m -> conditions , ] , null , $ e ) ; } if ( ! $ data ) { return ; } if ( ! isset ( $ data [ $ m -> id_field ] ) || is_null ( $ data [ $ m -> id_field ] ) ) { throw new Exception ( [ 'Model uses "id_field" but it wasn\'t available in the database' , 'model' => $ m , 'id_field' => $ m -> id_field , 'id' => $ id , 'data' => $ data , ] ) ; } $ m -> id = $ data [ $ m -> id_field ] ; return $ data ; }
Tries to load data record, but will not fail if record can't be loaded.

@param Model $m
@param mixed $id

@return array
Tries to load data record but will not fail if record can t be loaded .