You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class UserModel extends Model {
protected $table = 'users';
protected $returnType = User::class;
protected $allowedFields = ['id', 'name'];
}
I want to select only some fields.
$userModel = new UserModel();
$user = $userModel
->select('id')
->find(1);
I do some work on the entity and then I want to save the changes to the database. $userModel->save($user);
Because of the select, name is empty. The SQL generated is UPDATE `users` SET `id` = '1', `name` = NULL WHERE `users`.`id` IN ('1')
I have one idea for a fix. Make a copy of the properties in find and store the properties in a backup array in each entity. Then we can compare the backup property with the one to be saved and only save fields that are actually changed. This will however result in more memory usage.
The text was updated successfully, but these errors were encountered:
I have an User-entity with two properties:
And a UserModel
I want to select only some fields.
I do some work on the entity and then I want to save the changes to the database.
$userModel->save($user);
Because of the select, name is empty. The SQL generated is
UPDATE `users` SET `id` = '1', `name` = NULL WHERE `users`.`id` IN ('1')
I have one idea for a fix. Make a copy of the properties in
find
and store the properties in a backup array in each entity. Then we can compare the backup property with the one to be saved and only save fields that are actually changed. This will however result in more memory usage.The text was updated successfully, but these errors were encountered: