jeudi 22 mars 2018

Eloquent relationship two parent and child

I have three tables: 1. questionbank 2. questiontype 3. questions

I need to retrieve the json response :

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

My Models are:

  1. questionbank

    class Questionbank extends Model {

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

    }

  2. questiontype

    class questiontype extends Model {

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

    }

  3. questions

    class Questions extends 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() { return $this->hasManyThrough('App\QuestionBank', 'App\questiontype', 'QuestionBankID', 'QuestionTypeID', 'QuestionBankID', 'QuestionTypeID'); } }

i got the error:

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` 



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2pxlJSV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire