Welcome Guest, Not a member yet? Register   Sign In
Cancel $model->save($data) operation using $beforeInsert
#6

In the model, set the protected $primaryKey to the primary key of your table.

Then when you use the $model->save( $data ) method - if there is a value set for an array element in the $data that matches the $primaryKey the model will update the record if it does not exist the save method will insert a record.

Another method is to call either $model->insert($data) or $model->update( $yourPrimaryKey, $data ) depending on whether the record exists or not

Hope that helps.
Dirk B.
Abatrans Software
No SEO spam - see forum guidelines
Reply


Messages In This Thread
RE: Cancel $model->save($data) operation using $beforeInsert - by abatrans - 01-13-2020, 07:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB