Welcome Guest, Not a member yet? Register   Sign In
DB Insert Timing
#7

(This post was last modified: 01-17-2023, 11:11 AM by SoccerGuy3.)

(01-16-2023, 09:03 PM)kenjis Wrote: Check your real SQL statements with Debug Toolbar or DB Server log.

Code:
INSERT INTO `auction_lots_versions` (`parent_id`, `created_at`, `createdby_id`)
VALUES ('5297', '2023-01-17 09:55:09', '8')


Ok that tells me what is going on. CI is overriding and putting the 'created_at' in there, rather than allowing MariaDB to do it as I thought it was doing. I remember reading something about that in the docs. Off to find it! 

Thanks Kenjis you are always so helpful!! I very much appreciate it!

So looking at my Model, I see I included the "created_at" field in the allowed fields. Simply removing this solves the issue and allows MariaDB to set the timestamps.
PHP Code:
namespace App\Models;

class 
LotsVersionModel extends \CodeIgniter\Model
{
 protected 
$table 'auction_lots_versions';

 protected 
$allowedFields = [
 
'parent_id','created_at','createdby_id','update_reason','lot_num_temp','lot_num_final',
 
'consigner_id','market_id','rep_id_1','rep_id_2','rep_id_3','location_id','location_cs_id',
 .
 .
 .
 
'orig_contract_name','location_state'
 
];

Looking into the docs, I get the impression that I needed to explicitly allow CI to set the created_at timestamp. Am I missing something?

Quote:
Quote:$createdField
Specifies which database field to use for data record create timestamp. Leave it empty to avoid updating it (even if $useTimestamps is enabled).
Since I don't specify the field, shouldn't it NOT set the timestamp?
Reply


Messages In This Thread
DB Insert Timing - by SoccerGuy3 - 01-16-2023, 03:59 PM
RE: DB Insert Timing - by kenjis - 01-16-2023, 04:49 PM
RE: DB Insert Timing - by SoccerGuy3 - 01-16-2023, 04:59 PM
RE: DB Insert Timing - by kenjis - 01-16-2023, 05:20 PM
RE: DB Insert Timing - by SoccerGuy3 - 01-16-2023, 05:26 PM
RE: DB Insert Timing - by kenjis - 01-16-2023, 09:03 PM
RE: DB Insert Timing - by SoccerGuy3 - 01-17-2023, 10:58 AM
RE: DB Insert Timing - by kenjis - 01-17-2023, 06:37 PM
RE: DB Insert Timing - by SoccerGuy3 - 01-18-2023, 07:33 AM
RE: DB Insert Timing - by InsiteFX - 01-18-2023, 12:22 AM
RE: DB Insert Timing - by kenjis - 01-18-2023, 06:04 PM
RE: DB Insert Timing - by SoccerGuy3 - 01-27-2023, 11:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB