I want to do bulk insert and update to my custom model collection, right now I can only do insert multiple records to DB like this:
public function __construct(
\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor,
\Magento\Framework\App\ResourceConnection $resource
) {
$this->connection = $resource->getConnection();
$this->resource = $resource;
}
public function execute(){
$data[]['name'] = 'Bond'
$data[]['code'] = '007';
$data[]['name'] = 'Lancelot';
$data[]['code'] = '002';
$this->connection->insertMultiple($this->resource->getTableName('agent'), $data);
}
this will add those 2 data records to my database table agent
, the problem is when I execute this multiple time it will insert new data, I want to update the data if the code
column is same
code
is not primary key, this table doesn't have primary key