Welcome Guest, Not a member yet? Register   Sign In
updated_at is not updating
#8

(This post was last modified: 08-19-2021, 10:38 AM by wdeda. Edit Reason: Justification for two Models. )

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,
update_at DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL

@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

// 2021015

namespace App\Models;

use 
CodeIgniter\Model;

class 
RecordStylesModel extends Model
{

    public function styles($id)
    {
        $db $this->db;
        $query $db->table('record_styles')
        ->where('record_id'$id)
        ->get();

        return $query->getResult();

    }

    public function numstyles($id)
    {

        $db $this->db;
        $countall $db->table('record_styles');        
        $countall
->where('record_id'$id);

        return $countall->countAllResults();
    }


2 - for updating tables, inserting data.
PHP Code:
<?php

namespace App\Models\People;

use 
CodeIgniter\Model;

class 
AllNamesModel extends Model
{
 protected 
$DBGroup              'default';
 protected 
$table                'names';
 protected 
$primaryKey          'id';
 protected 
$useAutoIncrement    true;
 protected 
$insertID            0;
 protected 
$returnType          'array';
 protected 
$useSoftDeletes      false;
 protected 
$protectFields        true;
 protected 
$allowedFields        = [
 
'cover''name''shortbio''dupname''vip''dborn''mborn''yborn''bornplace''ddeath''mdeath''ydeath''deathplace''tab0''tab1''tab2''tab3''tab4''active''formed''disband'
 
];


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.
Reply


Messages In This Thread
updated_at is not updating - by nneves - 08-18-2021, 04:50 PM
RE: updated_at is not updating - by InsiteFX - 08-19-2021, 01:34 AM
RE: updated_at is not updating - by nneves - 08-19-2021, 02:21 AM
RE: updated_at is not updating - by ikesela - 08-19-2021, 04:12 AM
RE: updated_at is not updating - by nfaiz - 08-19-2021, 04:59 AM
RE: updated_at is not updating - by nneves - 08-19-2021, 05:25 AM
RE: updated_at is not updating - by ikesela - 08-19-2021, 12:12 PM
RE: updated_at is not updating - by craig - 08-19-2021, 07:52 AM
RE: updated_at is not updating - by wdeda - 08-19-2021, 10:28 AM
RE: updated_at is not updating - by nneves - 08-19-2021, 01:43 PM
RE: updated_at is not updating - by InsiteFX - 08-20-2021, 01:27 AM
RE: updated_at is not updating - by paliz - 08-20-2021, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB