Welcome Guest, Not a member yet? Register   Sign In
Entity with Model finder (custom setters)
#1

(This post was last modified: 10-09-2022, 04:54 AM by ozornick.)

I decided to get rid of dynamic properties in objects and added setters/getters
Now when the Model is executed, my new private properties are not initialized
// Role
private string $role;
private string $title;
private array $rules = [];

I found the reason in generating the result:

// vendor/codeigniter4/framework/system/Database/MySQLi/Result.php
protected function fetchObject(string $className = 'stdClass')
{
if (is_subclass_of($className, Entity::class)) {
return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data);
}

return $this->resultID->fetch_object($className);
}

Thus, setters are not used.
How can this behavior be corrected? Overload the setAttributes() method?

I found commit from iRedds https://github.com/codeigniter4/CodeIgni...35814e8dcc
What was the reason for this introduction?

P.S Sorry for the formatting - the post editor on the forum is broken.
Simple CI 4 project for beginners codeigniter-expenses
Reply


Messages In This Thread
Entity with Model finder (custom setters) - by ozornick - 10-09-2022, 04:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB