The code can work.
$user = \App\Models\User::findFirst([
'conditions' => 'id=?0',
'bind' => [24],
]);
$user->username = Str::quickRandom(12);
$res = $user->save();
The code can't work.
$user = \App\Models\User::findFirst([
'conditions' => 'id=?0',
'bind' => [24],
'columns' => 'id,username',
]);
$user->username = Str::quickRandom(12);
$res = $user->save();
~~~
atal error: Uncaught Error: Call to undefined method Phalcon\Mvc\Model\Row::save() in /Users/limx/Applications/php/phalcon/app/tasks/Test/MysqlTask.php:56
Stack trace:
thrown in /Users/limx/Applications/php/phalcon/app/tasks/Test/MysqlTask.php on line 56
~~~
When I update model, the sql update all field everytime. I want the sql only update the field changed.
Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.1.2
Build Date => Apr 12 2017 12:46:24
Powered by Zephir => Version 0.9.7-1fae5e50ac
Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
`)
PHP 7.0.20 (cli) (built: Jun 25 2017 00:04:15) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.20, Copyright (c) 1999-2017, by Zend Technologies
)You need to select full model like without columns option. When you are selecting model with columns then always Phalcon\Mvc\Model\Row is returned. It's not a bug.
but i don't need full columns for network consumption
@buddy-yao Then it is not pure entity (model) it is result set (row)
@sergeyklay yes!
i want to update the record after querying, but the row object can not updated, so i use the PHQL to update the record.