public function insert(Model $m, $data)
    {
        $insert = $m->action('insert');

        // don't set id field at all if it's NULL
        if ($m->id_field && array_key_exists($m->id_field, $data) && $data[$m->id_field] === null) {
            unset($data[$m->id_field]);
        }

        $insert->set($this->typecastSaveRow($m, $data));

        $st = null;

        try {
            $m->hook('beforeInsertQuery', [$insert]);
            $st = $insert->execute();
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to execute insert query',
                'query'      => $insert->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        $m->hook('afterInsertQuery', [$insert, $st]);

        return $m->lastInsertID();
    }
public function insert(Model $m, $data)
    {
        $insert = $m->action('insert');

        // don't set id field at all if it's NULL
        if ($m->id_field && array_key_exists($m->id_field, $data) && $data[$m->id_field] === null) {
            unset($data[$m->id_field]);
        }

        $insert->set($this->typecastSaveRow($m, $data));

        $st = null;

        try {
            $m->hook('beforeInsertQuery', [$insert]);
            $st = $insert->execute();
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to execute insert query',
                'query'      => $insert->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        $m->hook('afterInsertQuery', [$insert, $st]);

        return $m->lastInsertID();
    }
public function insert ( Model $ m , $ data ) { $ insert = $ m -> action ( 'insert' ) ; // don't set id field at all if it's NULL if ( $ m -> id_field && array_key_exists ( $ m -> id_field , $ data ) && $ data [ $ m -> id_field ] === null ) { unset ( $ data [ $ m -> id_field ] ) ; } $ insert -> set ( $ this -> typecastSaveRow ( $ m , $ data ) ) ; $ st = null ; try { $ m -> hook ( 'beforeInsertQuery' , [ $ insert ] ) ; $ st = $ insert -> execute ( ) ; } catch ( \ PDOException $ e ) { throw new Exception ( [ 'Unable to execute insert query' , 'query' => $ insert -> getDebugQuery ( false ) , 'model' => $ m , 'conditions' => $ m -> conditions , ] , null , $ e ) ; } $ m -> hook ( 'afterInsertQuery' , [ $ insert , $ st ] ) ; return $ m -> lastInsertID ( ) ; }
Inserts record in database and returns new record ID.

@param Model $m
@param array $data

@return mixed
Inserts record in database and returns new record ID .