mrardiyansyah Junior Member
Posts: 10
Threads: 5
Joined: Sep 2020
Reputation:
1
I am wondering why when I insert data using "insertBatch" the create_at field is still NULL?
is there anyone here can explain it?
nc03061981 Member
Posts: 173
Threads: 24
Joined: Jun 2015
Reputation:
2
10-04-2020, 02:11 AM
(This post was last modified: 10-04-2020, 02:15 AM by nc03061981 .)
You have some code
Set this:
$this->$useTimestamps = true;
$this = $yourModel
Learning CI4 from my works, from errors and how to fix bugs in the community
Love CI & Thanks CI Teams
paulbalandan External Auditor
Posts: 295
Threads: 10
Joined: Jul 2020
Reputation:
25
Did you include the created at field in the allowed fields?
mrardiyansyah Junior Member
Posts: 10
Threads: 5
Joined: Sep 2020
Reputation:
1
(10-31-2020, 06:19 AM) paulbalandan Wrote: Did you include the created at field in the allowed fields?Of course, I did. Same as in the documentaion.
PHP Code:
protected $useTimestamps = true ; protected $useSoftDeletes = true ; protected $createdField = 'created_at' ; protected $updatedField = 'updated_at' ; protected $deletedField = 'deleted_at' ;
paulbalandan External Auditor
Posts: 295
Threads: 10
Joined: Jul 2020
Reputation:
25
Can you post your model code?
wdeda Member
Posts: 135
Threads: 5
Joined: Dec 2014
Reputation:
1
11-01-2020, 01:09 PM
(This post was last modified: 11-01-2020, 02:27 PM by wdeda .)
I had the same problem, which is intermittent, because it occurs in certain processes and not in others, without any indication of why. I also noticed that when there are no problems it updates both the created_at and updated_at fields, with exactly the same date and time. The solution I found was to define created_at, update_at and deleted_at, with a null value; created_at plus null with default "current timestamp" and "updated_at" plus null with attribute "n update current timestamp"
The update is done via form, as below.
Model:
PHP Code:
<?php namespace App \ Models ; // 20200512 use CodeIgniter \ Model ; class ArtistsMoviesModel extends Model { protected $table = 'artist_movie' ; protected $primaryKey = 'id' ; protected $returnType = 'object' ; protected $Timestamps = true ; protected $useSoftDeletes = true ; protected $allowedFields = [ 'artist_id' , 'movie_id' , 'position' , 'charact' , 'act1' , 'act2' , 'act3' , 'act4' , 'act5' ]; }
Controller:
PHP Code:
public function artmov () { helper ( 'form' ); $model = new ArtistsMoviesModel (); $header = array( 'icon' => 'favicon' , 'css' => 'tables' , 'title' => 'Atualização da tabela \'artist_movie\' - wdeda' , 'action' => '/search/allmedia/' , 'placeholder' => 'Pesquisar' ); $rules = [ 'artist_id' => 'required' , 'movie_id' => 'required' ]; if ( $this -> validate ( $rules )) { $model -> insert ([ 'artist_id' => $this -> request -> getVar ( 'artist_id' ), 'movie_id' => $this -> request -> getVar ( 'movie_id' ), 'position' => $this -> request -> getVar ( 'position' ), 'charact' => $this -> request -> getVar ( 'charact' ), 'act1' => $this -> request -> getVar ( 'act1' ), 'act2' => $this -> request -> getVar ( 'act2' ), 'act3' => $this -> request -> getVar ( 'act3' ), 'act4' => $this -> request -> getVar ( 'act4' ), 'act5' => $this -> request -> getVar ( 'act5' ), ]); echo view ( 'templates/headerx' , $header ); echo view ( 'tables/artmov-success' ); echo view ( 'templates/footerfb' ); } else { echo view ( 'templates/headerx' , $header ); echo view ( 'utils/artmov' ); echo view ( 'templates/footerfb' ); } }
View:
PHP Code:
<!-- 20200514 --> < div class= "content-container" > < section class= "section-tools" > < h4 ></ h4 > < div class= "form-content" > < form method = "post" action = "/tables/artmov/" > < table cellpadding = "0" cellspacing = "1" style = "width: 90%;" > < tr > < td class= "tdright" > Artist_id :</ td > < td class= "tdleft" >< input name = "artist_id" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Movie_id :</ td > < td class= "tdleft" >< input name = "movie_id" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Posição :</ td > < td class= "tdleft" >< input name = "position" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Personagem :</ td > < td class= "tdleft" >< input name = "charact" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Act1 :</ td > < td class= "tdleft" >< input name = "act1" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Act2 :</ td > < td class= "tdleft" >< input name = "act2" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Act3 :</ td > < td class= "tdleft" >< input name = "act3" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Act4 :</ td > < td class= "tdleft" >< input name = "act4" size = "10" /></ td > </ tr > < tr > < td class= "tdright" > Act5 :</ td > < td class= "tdleft" >< input name = "act5" size = "10" /></ td > </ tr > < tr > < tr > < td class= "tdright" style = "padding-top:10px" >< input type = "submit" name = "submit" value = "Submit" /></ td > </ tr > </ table > </ form > </ div > < ul > < div class= "tab-content" > < div class= "filters" > < h3 > Última Atualização </ h3 > <? php $db = db_connect (); $query = $db -> table ( 'names' ) -> orderBy ( 'id' , 'desc' ) -> limit ( '1' ) -> get (); foreach ( $query -> getResult () as $row ); ?> <ul> <li class="li-all"> <span class="span-all">Id:<span class='wd-space'> </span><?php echo $row -> id ; ?> <br /> <span class="span-all">Nome:<span class='wd-space'> </span><?php echo $row -> name ; ?> <br /> </li> <?php $db = db_connect (); $query = $db -> table ( 'movies' ) -> orderBy ( 'id' , 'desc' ) -> limit ( '1' ) -> get (); foreach ( $query -> getResult () as $row ); ?> <li class="li-all"> <span class="span-all">Id:<span class='wd-space'> </span><?php echo $row -> id ; ?> <br /> <span class="span-all">Título:<span class='wd-space'> </span><?php echo $row -> title ; ?> <br /> </li> </ul> <div class="validation my-3 btn-warning"> <?php echo \ Config \ Services :: validation ()-> listErrors () ?> </div> </section> </div>
Attached Files
Thumbnail(s)