Duplication in create/save() when app is stopping

I create some data from model : ```php <?php $record = new Records(); // ... $record->create() ``` Now, when I stop my app (or I have some errors) - for example: ```php <?php print_r($record->id); exit(); ``` App does not add a single record, but two. Why this is work like that?



81.8k

Can you please provide a script like this: https://gist.github.com/phalcon/5610396 making us able to reproduce your problem?

Well, there is no problem for me, because my app works fine. I noticed it by chance and I ask out of curiosity - it is a bug or not?

There is very standard configuration, so I paste only controller and model. (Phalcon V 1.1/nginx/php5.4)

<?php namespace Front\Controllers;

class TestController extends \Phalcon\Mvc\Controller
{

    public function indexAction()
    {

        $record = new \Models\Records();
        $record->module = 1;
        $record->create();
        $id = $record->id;
        print_r($id);
        exit();

    }
}
<?php namespace Models;

class Records extends \Phalcon\Mvc\Model
{

    public $id;
    public $module;

    public function getSource()
    {
        return 'records';
    }

}

CREATE TABLE IF NOT EXISTS records (id int(10) unsigned NOT NULL AUTOINCREMENT, module tinyint(3) unsigned NOT NULL, PRIMARY KEY (id), KEY module (module)) ENGINE=InnoDB AUTOINCREMENT=1 ;



81.8k

This is clearly not a bug, but for the sake of clarity, this is your code: https://gist.github.com/phalcon/5886245 and it's running here: http://test.phalconphp.com/create.php as you can see just a single insert is made. And the "End example (never executed)<br>" is not being printed because of the call to 'exit'.

In addition, there are unit-tests for that like these: https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L302, running and passing on 3 different versions of PHP (https://www.travis-ci.org/phalcon/cphalcon) (without mention the active applications and functionality that depends on that).