Phalcon won't update record anyway

I'm using Model and PHQL to update a record but mysql wont accept any changes. select and insert works properly.

sample update with PHQL:

UPDATE \Modules\Shared\Models\Airline SET [name] = 'test' WHERE id = '8'

Could you provide sample code and db structure if that's not a problem?

Simpled code i've used using model:

            $object = Airline::findFirst($id);

            $post = $this->request->getPost();

            $object->name = $post['name'];
            $object->lata = $post['lata'];
            $object->language = $post['language'];
            $object->parent_id = $post['parent_id'] ?: NULL;

            $object->update();
            foreach ($object->getMessages() as $m) {
                echo $m. '<br>';
            }

Model and db structure:

class Airline extends \Phalcon\Mvc\Model
{

  /**
  * @var integer
  */
  public $id;

  /**
  * @var string
  */
  public $name;

  /**
  * @var string
  */
  public $lata;

  /**
  * @var string
  */
  public $language;

  /**
  * @var integer
  */
  public $parent_id;


  public function initialize()
  {
      $this->setSource('sh_airlines');
 }

Could you provide sample code and db structure if that's not a problem?



30.7k

Hi,

are you sure that you've got a valid id for querying $object = Airline::findFirst($id);

edited Oct '15

Hi

Yes! I'm sure.

also post data was checked and are valid.

Hi,

are you sure that you've got a valid id for querying $object = Airline::findFirst($id);



30.7k

ok,

does $object = Airline::findFirst($id); return a valid model object ?

Also try with

$object->save();

Yes. $object rerturns a vaild object. save() has a same result..

ok,

does $object = Airline::findFirst($id); return a valid model object ?

Also try with

$object->save();



30.7k

that's really strange.

Try to debug your sql save statement to see what happens during $object->save() (or update())

(https://docs.phalconphp.com/en/latest/reference/models.html#logging-low-level-sql-statements)

edited Oct '15

oOOPS !

result:

[Mon, 26 Oct 15 17:00:52 +0330][INFO] UPDATE sh_airlines SET id = ?, lata = ?, language = ?, parent_id = ? WHERE name = ?

is it normal?!


edit:

logging of Insert also have question mark instead of values

[Mon, 26 Oct 15 21:07:37 +0330][INFO] INSERT INTO sh_airlines (name, lata, language, parent_id) VALUES (?, ?, ?, ?)

It is normal, this is params binding in PDO.

Can you try something like:

var_dump($object->update());
foreach ($object->getMessages() as $m) {
    echo $m. '<br>';
}
exit;

This is from the first code box in your comment https://forum.phalconphp.com/discussion/9131/phalcon-wont-update-record-anyway#C25077

note the exit after foreach loop;