![]() |
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()) {
Where is the line 685? What is the Entity Object?
The error message shows you are doing wrong to the array key.
If I use array not entity it works fine.
This function is inside "vendor\codeigniter4\framework\system\Model.php" PHP Code: /**
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. (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: /**
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.
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);
I concluded this is a bug.
I sent a PR to fix this bug. https://github.com/codeigniter4/CodeIgniter4/pull/8670 |
Welcome Guest, Not a member yet? Register Sign In |