如何在Phalcon MVC模型之间建立子父关系?
这是我想到的数据库模式:
explain show;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| length | int(11) | NO | | NULL | |
| title | varchar(100) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
explain show_episode;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| show_id | int(11) | NO | PRI | NULL | |
| season | int(11) | NO | | NULL | |
| episode | int(11) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
show_episode
中的每个元素也存在于show
表中,但是有些显示记录仅存在于show
中。
这个想法是有两个Phalcon模型类:
class Show extends Phalcon'Mvc'Model
{
public $id;
public $length;
public $title;
}
class ShowEpisode extends Show
{
public $season;
public $episode;
}
我需要如何配置这些模型才能像这样检索和保存剧集记录:
// retrieve
$episode = ShowEpisode::findFirst(array("id"=>333));
echo $episode->season;
echo $episode->title;
// save
$episode->title = "New Title";
$episode->season = 3;
$episode->save();
你看过吗?
class Show extends Phalcon'Mvc'Model
{
public $id;
public $length;
public $title;
public function initialize()
{
$this->hasMany("id", "Episode", "showid", NULL);
}
}
还是类似的东西?