雄辩关系两个父母和孩子

时间:2018-03-22 07:22:39

标签: laravel-5 eloquent laravel-eloquent

我有三张桌子:1。问题库2.问题类型3.问题

我需要检索json响应:

[{"questiontitle":"OSCE","questionbank":"osce bank","questiontype":"osce type"}]

我的模特是:

  1. 试题库

    类Questionbank扩展了模型{

    protected $fillable = [];
    
    protected $table = "QuestionBank";
    
    protected $dates = [];
    protected $primaryKey = "QuestionBankID";
    
    protected $visible = ["QuestionBank"];
    
    public static $rules = [
        // Validation rules
    ];
    

    }

  2. questiontype

    class questiontype扩展了Model {

    protected $fillable = [];
    
    protected $dates = [];
    
    protected $table = "QuestionType";
    
    protected $primarykey = "QuestionTypeID";
    
    protected $visible = ["QuestionType"];
    
    public static $rules = [
        // Validation rules
    ];
    
    // Relationships
    

    }

  3. 问题

    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');     } }

  4. 我收到了错误:

    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` 
    

0 个答案:

没有答案