我有三张桌子:1。问题库2.问题类型3.问题
我需要检索json响应:
[{"questiontitle":"OSCE","questionbank":"osce bank","questiontype":"osce type"}]
我的模特是:
试题库
类Questionbank扩展了模型{
protected $fillable = [];
protected $table = "QuestionBank";
protected $dates = [];
protected $primaryKey = "QuestionBankID";
protected $visible = ["QuestionBank"];
public static $rules = [
// Validation rules
];
}
questiontype
class questiontype扩展了Model {
protected $fillable = [];
protected $dates = [];
protected $table = "QuestionType";
protected $primarykey = "QuestionTypeID";
protected $visible = ["QuestionType"];
public static $rules = [
// Validation rules
];
// Relationships
}
问题
class Questions扩展了Model {
protected $fillable = ["QuestionTitle"];
protected $dates = [];
protected $primaryKey = "QuestionID";
protected $foreignKey = "QuestionBankID";
public static $rules = [
// Validation rules
];
protected $visible = ["QuestionTitle","QuestionBank","QuestionType"];
// Relationships
public function QuestionBank(){ 返回$ this-> hasManyThrough('App \ QuestionBank','App \ questiontype','QuestionBankID','QuestionTypeID','QuestionBankID','QuestionTypeID'); } }
我收到了错误:
Column not found: 1054 Unknown column 'QuestionType.QuestionBankID' in 'field list' (SQL: select `QuestionBank`.*, `QuestionType`.`QuestionBankID` from `QuestionBank` inner join `QuestionType` on `QuestionType`.`QuestionTypeID` = `QuestionBank`.`QuestionTypeID` where `QuestionType`.`QuestionBankID`