如何在 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();