Exam Question/Answer 3-way m:n
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php namespace GermanAirlinesVa\Schooling\Models;
|
||||
|
||||
use Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* Model
|
||||
@@ -33,4 +34,29 @@ class ExamTyperatingAnswer extends Model
|
||||
public $belongsTo = [
|
||||
'exam_question' => ['GermanAirlinesVa\Schooling\Models\ExamTyperatingQuestion', 'key' => 'exam_question_id'],
|
||||
];
|
||||
|
||||
public $belongsToMany = [
|
||||
'exam_typeratings' => [
|
||||
'GermanAirlinesVa\Schooling\Models\ExamTyperating',
|
||||
'table' => 'exam_exam_answer_exam_question',
|
||||
'key' => 'exam_answer_id',
|
||||
'otherKey' => 'exam_id',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The "booting" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('exam_typerating_answer_typerating_id', function (Builder $builder) {
|
||||
$builder->whereHas('exam_question', function ($query) {
|
||||
$query->where('typerating_id', '<>', null);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user