CodeIgniter Forums
$model update function always returns 1 even not data updated - 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: $model update function always returns 1 even not data updated (/showthread.php?tid=80180)



$model update function always returns 1 even not data updated - 2k10cs86 - 09-24-2021

Hello,
As example mentioned in the documentation:
In Documentation:
$userModel
    ->whereIn('id', [1,2,3])
    ->set(['active' => 1])
    ->update();


Changes:

$result = $this->modelPsVotes
                    ->where('fk_id'$fkId1)
                    ->where('fk_id'$fkId2)
                    ->set(['name' => 'Test'])
                    ->update();

but if I save the value in the variable $result and print it always 1, even the data is not updated. 

Any suggestion?


RE: $model update function always returns 1 even not data updated - iRedds - 09-24-2021

1 = true
true = Query was executed without errors
use the affectedRows() method to control changes


RE: $model update function always returns 1 even not data updated - 2k10cs86 - 09-25-2021

Thanks for the answer, but affectedRows() function is not in the model.


RE: $model update function always returns 1 even not data updated - iRedds - 09-25-2021

Use $this->modelPsVotes->db->affectedRows()

Error with $this->modelPsVotes->affectedRows() - bug


RE: $model update function always returns 1 even not data updated - 2k10cs86 - 09-26-2021

(09-25-2021, 11:37 PM)iRedds Wrote: Use $this->modelPsVotes->db->affectedRows()

Error with $this->modelPsVotes->affectedRows() - bug

Thank you so much, that is very helpful.