我在两个表之间有 has_many 关系,例如:“questions”-<“options”[一个问题有很多选项] 我的班级结构是:for question
class Model_Admin_sysQuestion extends ORM {
protected $_table_name = 'questions';
protected $_has_many = array(
'options' => array(
'model' => 'Admin_sysQuestionOption',
'foreign_key' => 'question_id',
),
);... .
对于选项
Class Model_Admin_sysQuestionOption extends ORM {
protected $_table_name = 'questions_options';
protected $_belongs_to = array(
'question' => array(
'model' => 'Admin_sysSection',
'foreign_key' => 'question_id',
),
); .... .
我试图使用以下代码删除所有选项的问题:
$question = ORM::factory('Admin_sysQuestion', 30);
$question->options->delete($question->id);
$question->delete();
但它给出了错误
错误":"无法删除 admin_sysquestionoption 模型,因为它没有加载。"
任何想法?怎么做?