CodeIgniter Forums
ResourceController and model->update, is this a bug - 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: ResourceController and model->update, is this a bug (/showthread.php?tid=80243)



ResourceController and model->update, is this a bug - rich8374 - 10-05-2021

Hi, I'm getting errors when trying to do a database update in a ResourceController, some ways work and some ways throw errors. Is this a bug?
Using CodeIgniter 4.1.4, here is a simplified example, I've commented out the lines which throw errors.
PHP Code:
namespace App\Controllers;

use 
CodeIgniter\RESTful\ResourceController;

class 
Feedback extends ResourceController
{
    protected $modelName 'App\Models\FeedbackModel';
    protected $format    'json';

    public function index()
    {
        $db = \Config\Database::connect();
        // works
        $db->table('feedback')->update(['score' => '20'], "id = 1");
        // works
        $db->table('feedback')->update(['score' => '21'], ['id' => 1]);
        // TypeError, Return value of CodeIgniter\\BaseModel::transformDataToArray() must be of the type array, string returned
        //$this->model->update(['score' => '22'], "id = 1");
        // DataException, There is no data to update
        //$this->model->update(['score' => '23'], ['id' => 1]);
        // Works
        $this->model->set('score''24');
        $this->model->where('id'1);
        $this->model->update();
    }

Does anyone know why model->update() throws those errors?
Thanks.


RE: ResourceController and model->update, is this a bug - iRedds - 10-05-2021

BaseBuilder::update() !== BaseModel::update()


RE: ResourceController and model->update, is this a bug - paliz - 10-05-2021

see

PHP Code:
use CodeIgniter\RESTful\ResourceController;

class 
Feedback extends ResourceController
{
    protected $modelName 'App\Models\FeedbackModel';
    protected $format    'json';

    public function index()
    {
    
$model 
= new Model();
        $model->update($id,['some'=>'thing']);
    }