Before running this, you'll need to create the database:
$ mysql
...
mysql> create database issue13354;
Before running this, you'll need to create the database:
$ mysql
...
mysql> create database issue13354;
<?php | |
$di = new \Phalcon\Di\FactoryDefault(); | |
$di->setShared('db', function () { | |
return new \Phalcon\Db\Adapter\Pdo\Mysql([ | |
'host' => 'localhost', | |
'username' => 'root', | |
'password' => 'root', | |
'dbname' => 'issue13354', | |
]); | |
}); | |
$di['db']->execute(<<<SQL | |
DROP TABLE IF EXISTS `robot`; | |
DROP TABLE IF EXISTS `part`; | |
CREATE TABLE `robot` ( | |
id INT NOT NULL AUTO_INCREMENT, | |
name VARCHAR(255), -- stop ORM throwing when no fields to save | |
PRIMARY KEY (id) | |
); | |
CREATE TABLE `part` ( | |
id INT NOT NULL AUTO_INCREMENT, | |
robot_id INT NOT NULL, | |
PRIMARY KEY (id) | |
); | |
SQL); | |
class Robot extends \Phalcon\Mvc\Model | |
{ | |
public function initialize() | |
{ | |
$this->hasMany('id', 'Part', 'robot_id', [ | |
'alias' => 'Parts' | |
]); | |
} | |
} | |
class Part extends \Phalcon\Mvc\Model | |
{ | |
public function initialize() | |
{ | |
$this->belongsTo('robot_id', 'Robot', 'id'); | |
} | |
} | |
// Repro | |
$robot = new Robot(); | |
$part = new Part(); | |
$robot->parts = [$part]; | |
$part->robot = $robot; | |
echo "Going to save..\n"; | |
$robot->save(); // <-- segfaults | |
echo "Finished executing\n"; |