CodeIgniter Forums
Update and There is no data to update. - 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: Update and There is no data to update. (/showthread.php?tid=87631)



Update and There is no data to update. - serialkiller - 05-11-2023

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


RE: Update and There is no data to update. - vido - 12-31-2023

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.


RE: Update and There is no data to update. - kenjis - 02-03-2024

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/models/model.html#update