Welcome Guest, Not a member yet? Register   Sign In
Update and There is no data to update.
#1

(This post was last modified: 05-11-2023, 07:55 AM by serialkiller.)

I can't figure out where the problem is.
I set the model parameters

PHP Code:
protected $table         'myTable';

protected 
$primaryKey    'id';

protected 
$returnType    'object';

protected 
$allowedFields = [
    'field_a',
    'field_b',
    'filed_c',
    'filed_d',
    'field_e',
]; 


Now, inside a method

PHP Code:
$data_update = [
                'filed_a' => '',
                'field_b' => 0,
                'field_c' => date('Y-m-d H:i:s')
               ];

$this->where('id'$row->id)->update($data_update); // <= There is no data to update.

$this->set($data_update)->where('id'$row->id)->update(); // <= Works 

I don't do both updates, both are written to show the two types of approach

$row->id has a value and is correct
What goes wrong when I don't use set()

I've used update() thousands of times, but I don't understand what's going on here

Codeigniter version 4.3.4
Reply
#2

I have the same problem. Codeigniter version 4.4.3. It should be a bug of some sort. According to the documentation it should work.
I'm happy I saw your post and I used 'set' as a workaround. Just moved the data from 'update' to 'set' and everything works.
Reply
#3

You are confusing Model's update() and Query Builder's update().
If you use Model, the update() method needs two parameters (or zero).
See https://www.codeigniter.com/user_guide/m...tml#update
Reply




Theme © iAndrew 2016 - Forum software by © MyBB