mercredi 29 juin 2016

How can I force a timestamp update in Laravel 5.1 when performing a raw INSERT ... ON DUPLICATE KEY UPDATE?


I use DB::statement($query, $params) to perform batch inserts into my database with the INSERT ... ON DUPLICATE KEY UPDATE syntax. However, when I do, neither the 'updated_at' or 'created_at' fields are updated. I am wondering if there is a way to force the correct field to be updated in the raw query?

Context: I am using Laravel 5.1 and have created the relevant tables using the $table->timestamps() feature. In addition to doing raw insert/updates, I also query these tables using Eloquent so I cannot implement a solution that would disable Eloquent's auto-updates.

Concerns: I am not clear at the moment how times are generated when Eloquent automatically updates a timestamp field - I assume it triggers an auto-update in the database with reference to the database's reference clock? I would like to mimic however Eloquent is going about it so that I don't end up with times using two different clocks as sources.

I am very new to using raw MySQL queries so appreciate in advance any advice/insight folks are able to offer! Thank you!


Aucun commentaire:

Enregistrer un commentaire