Codeigniter 4 Model set() returns error - 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: Codeigniter 4 Model set() returns error (/showthread.php?tid=90502) |
Codeigniter 4 Model set() returns error - MZahov - 03-27-2024 Input: Entity Object Error returned: "Illegal offset type" on line 685 in \codeigniter4\framework\system\Model.php. Example: PHP Code: if ((new EquipmentModel)->where('order_id', $order_id)->first()) { RE: Codeigniter 4 Model set() returns error - kenjis - 03-27-2024 Where is the line 685? What is the Entity Object? The error message shows you are doing wrong to the array key. RE: Codeigniter 4 Model set() returns error - MZahov - 03-27-2024 If I use array not entity it works fine. This function is inside "vendor\codeigniter4\framework\system\Model.php" PHP Code: /** RE: Codeigniter 4 Model set() returns error - kenjis - 03-28-2024 As you see the first parameter of set() method is: PHP Code: @param array|object|string $key Field name, or an array of field/value pairs So you cannot pass an entity to the set() method. RE: Codeigniter 4 Model set() returns error - MZahov - 03-28-2024 (03-28-2024, 12:58 AM)kenjis Wrote: As you see the first parameter of set() method is: Shouldn't it be the same as BaseBuilder set() function ? PHP Code: /** RE: Codeigniter 4 Model set() returns error - kenjis - 03-28-2024 Oh, good point! I overlooked "@param object". If it accept an object, the description "Field name, or an array of field/value pairs" is not correct. But the current code does not accept an object. RE: Codeigniter 4 Model set() returns error - MZahov - 03-28-2024 For other people who encounter use of OBJECT in update() function based on foreign key. Solution/Transform object to array and use set($array): PHP Code: model()->where('foreign', $foreign)->update(null, $entity); RE: Codeigniter 4 Model set() returns error - kenjis - 03-28-2024 I concluded this is a bug. I sent a PR to fix this bug. https://github.com/codeigniter4/CodeIgniter4/pull/8670 |