Cphalcon: Model Update Error

Created on 25 Jun 2017  路  4Comments  路  Source: phalcon/cphalcon

Details

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:

0 [internal function]: App\Tasks\Test\MysqlTask->modelUpdateAction(Array)

1 [internal function]: Phalcon\Cli\Dispatcher->callActionMethod(Object(App\Tasks\Test\MysqlTask), 'modelUpdateActi...', Array)

2 [internal function]: Phalcon\Dispatcher->_dispatch()

3 [internal function]: Phalcon\Dispatcher->dispatch()

4 /Users/limx/Applications/php/phalcon/run(68): Phalcon\Cli\Console->handle(Array)

5 {main}

thrown in /Users/limx/Applications/php/phalcon/app/tasks/Test/MysqlTask.php on line 56
~~~

Suggest

When I update model, the sql update all field everytime. I want the sql only update the field changed.

  • Phalcon version: (`phalcon

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 Version: (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 )
  • Operating System:
  • Installation type: Compiling from source || installing via package manager
  • Zephir version (if any):
  • Server: Nginx
  • Other related info (Database, table schema):
not a bug

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings