Kohana 3 简单关系
-
04-10-2019 - |
题
解决方案
class Model_Article extends ORM{
protected $_belongs_to = array
(
'category' => array(), // This automatically sets foreign_key to category_id and model to Model_Category (Model_$alias)
);
}
class Model_Category extends ORM{
protected $_has_many = array
(
'articles' => array(), // This automatically sets foreign_key to be category_id and model to Model_Article (Model_$alias_singular)
);
}
您也可以手动定义关系;
'articles' => array('model'=>'article','foreign_key'=>'category_id');
不隶属于 StackOverflow