![]() |
updated_at is not updating - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: updated_at is not updating (/showthread.php?tid=79932) Pages:
1
2
|
updated_at is not updating - nneves - 08-18-2021 Hi In my model I have this settings and when I insert a record, both created_at and updated_at are updated Code: protected $table = 'strings'; When I run an update, the updated_at is not updated Code: $db = \Config\Database::connect(); Am I doing something wrong? Thanks RE: updated_at is not updating - InsiteFX - 08-19-2021 Did you add this to your model? PHP Code: /** RE: updated_at is not updating - nneves - 08-19-2021 Hi No, but does not change the behavior. In debug mode I can see that the insert query adds both created and updated dates, but when updating, the updated_at filed is not added. I've tested executing the query manually and using the builder. RE: updated_at is not updating - ikesela - 08-19-2021 this the problem, when you set to false, not working with updated_at (for auto update datetime). $builder->set('views', 'views+1', false); * this maybe bug RE: updated_at is not updating - nfaiz - 08-19-2021 (08-18-2021, 04:50 PM)nneves Wrote: Hi because you creating another builder? RE: updated_at is not updating - nneves - 08-19-2021 (08-19-2021, 04:12 AM)ikesela Wrote: this the problem, when you set to false, not working with updated_at (for auto update datetime). I've tested either with false, true or without any value and the updated_at field is not updated (08-19-2021, 04:59 AM)nfaiz Wrote: because you creating another builder? I can't use save/update because my primary key is composed with two fields. I've tried too with $db->query('UPDATE string SET views = views + 1 ... and doesn't work either ... RE: updated_at is not updating - craig - 08-19-2021 The inserted/updated fields are only set when you call methods on the model. Query Builder alone doesn't know about those, so won't touch them. RE: updated_at is not updating - wdeda - 08-19-2021 The update of created_at and/or updated_at is completely random, both in option 1 and option 2, I gave up on understanding why sometimes it happens and sometimes it doesn't, and when it happens, according to my point of view, it's kind of meaningless, this is, updates created_at and update_at simultaneously with the same data. I think update_at should only be updated when an update actually occurs. The solution I found was both in creating new tables and in existing tables using the following settings: Code: created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP, @craig I don't agree. I use "two types" of Model: 1 - for queries, query builder; I don't use find or find all; PHP Code: <?php 2 - for updating tables, inserting data. PHP Code: <?php Of course I could do it in a single Model but as what I have is a private site, only local, I have a second site dedicated only to table updates, 28 in total, and other support services, etc. RE: updated_at is not updating - ikesela - 08-19-2021 (08-19-2021, 05:25 AM)but nneves Wrote:(08-19-2021, 04:12 AM)ikesela Wrote: this the problem, when you set to false, not working with updated_at (for auto update datetime). I have this problem too before, when using this line: $builder->set('views', 'views+1', false); my noob solution is to turn off timestamp: $useTimestamps = false; then i did update updated_at manually . i hope there are solution in future to make it works when function is used ( problem maybe at builder). RE: updated_at is not updating - nneves - 08-19-2021 Yes, I've disable useTimestamps and just update the fields manually until a stable solution. Even so, there is an insert query that updates updated_at with useTimestamps = false. |