Model UPDATE on save() when must be INSERT

There is big problem with models in Phalcon 1.1. I have similar code like this: ```php class User extends \Phalcon\Mvc\Model { public $id;
public $email; function myCustomUserCreator(){ $newUser = new User(); $newUser->email= 'test'; if($newUser->save()==false){
return false; } else {
return $newUser->id; } } } print User::myCustomUserCreator(); ``` This code always execute UPDATE and on execution returns new values from mysql auto increment (1,2,3,4 etc.) This is very strange, because I wrote "new User()", what means that I have to INSERT new record in table with save(). Can somebody explain why it works so or it is some phalcon bug? In other frameworks (Yii, Zend) this works without problems.



84.1k

This is your code: https://gist.github.com/phalcon/5610308

I'm running it here: http://test.phalconphp.com/orm-1.php

As you can see, there are only INSERTs returning the numeric id generated by the database



12.0k

try to change Phalcon\Db\Adapter\Pdo\Sqlite as Connection, to Phalcon\Db\Adapter\Pdo\Mysql as Connection

I tried this code locally and it also try to update. If I write myCustomUserCreator function code outside User class, for example in controller action method then everything is fine.



84.1k

Code: https://gist.github.com/phalcon/5610396

Running: http://test.phalconphp.com/orm-2.php

SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME= 'user' AND TABLE_SCHEMA='test' SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='user' DESCRIBE user INSERT INTO user (email) VALUES (?) 5