phalcon-devtools
phalcon-devtools copied to clipboard
Foreign key
Phalcon DevTools v0.9.1
phalcon all-models --fk --relations
generates models like this
<?php
class Articles extends \Phalcon\Mvc\Model
{
public $id;
// ...
public function initialize()
{
$this->belongsTo("id", "Objects", "id");
$this->addForeignKey("id", "Objects", "id");
$this->addForeignKey("owner_id", "Objects", "id");
}
}
But method \Phalcon\Mvc\Model::addForeignKey doesn't exist. Is it deprecated?
If so, how should I set foreign keys?
It seems the generator is wrong, it must be:
<?php
class Articles extends \Phalcon\Mvc\Model
{
public $id;
// ...
public function initialize()
{
$this->belongsTo("owner_id", "Objects", "id", array(
'foreignKey' => true
));
}
}
Thank you
I updated a builder to support the new syntax and posted a pull request https://github.com/phalcon/phalcon-devtools/pull/123