protected function insertInternal($attributes = null, $connection = null)
    {
        if (!$this->beforeSave(true)) {
            return reject(false);
        }
        $values = $this->getDirtyAttributes($attributes);
        return static::getDb()->getSchema()->insert(static::tableName(), $values, $connection)->then(
            function($primaryKeys) use ($values) {
                if ($primaryKeys === false) {
                    return reject(false);
                }
                foreach ($primaryKeys as $name => $value) {
                    $id = static::getTableSchema()->columns[$name]->phpTypecast($value);
                    $this->setAttribute($name, $id);
                    $values[$name] = $id;
                }

                $changedAttributes = array_fill_keys(array_keys($values), null);
                $this->setOldAttributes($values);
                $this->afterSave(true, $changedAttributes);
                return true;
            }
        );
    }
protected function insertInternal($attributes = null, $connection = null)
    {
        if (!$this->beforeSave(true)) {
            return reject(false);
        }
        $values = $this->getDirtyAttributes($attributes);
        return static::getDb()->getSchema()->insert(static::tableName(), $values, $connection)->then(
            function($primaryKeys) use ($values) {
                if ($primaryKeys === false) {
                    return reject(false);
                }
                foreach ($primaryKeys as $name => $value) {
                    $id = static::getTableSchema()->columns[$name]->phpTypecast($value);
                    $this->setAttribute($name, $id);
                    $values[$name] = $id;
                }

                $changedAttributes = array_fill_keys(array_keys($values), null);
                $this->setOldAttributes($values);
                $this->afterSave(true, $changedAttributes);
                return true;
            }
        );
    }
protected function insertInternal ( $ attributes = null , $ connection = null ) { if ( ! $ this -> beforeSave ( true ) ) { return reject ( false ) ; } $ values = $ this -> getDirtyAttributes ( $ attributes ) ; return static :: getDb ( ) -> getSchema ( ) -> insert ( static :: tableName ( ) , $ values , $ connection ) -> then ( function ( $ primaryKeys ) use ( $ values ) { if ( $ primaryKeys === false ) { return reject ( false ) ; } foreach ( $ primaryKeys as $ name => $ value ) { $ id = static :: getTableSchema ( ) -> columns [ $ name ] -> phpTypecast ( $ value ) ; $ this -> setAttribute ( $ name , $ id ) ; $ values [ $ name ] = $ id ; } $ changedAttributes = array_fill_keys ( array_keys ( $ values ) , null ) ; $ this -> setOldAttributes ( $ values ) ; $ this -> afterSave ( true , $ changedAttributes ) ; return true ; } ) ; }
Inserts an ActiveRecord into DB without considering transaction.
@param array                    $attributes list of attributes that need to be saved. Defaults to `null`,
meaning all attributes that are loaded from DB will be saved.
@param ConnectionInterface|null $connection
@return ExtendedPromiseInterface with bool whether the record is inserted successfully.
Inserts an ActiveRecord into DB without considering transaction .