Skip to content

Instantly share code, notes, and snippets.

@stecman
Last active February 28, 2019 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stecman/5d4302fb293f9e7f7492e16c2f03bc65 to your computer and use it in GitHub Desktop.
Save stecman/5d4302fb293f9e7f7492e16c2f03bc65 to your computer and use it in GitHub Desktop.
Repro for Phalcon issue 13354 using MySQL

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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment