Exam Question/Answer 3-way m:n

This commit is contained in:
2021-08-13 21:07:55 +02:00
parent aa073a5029
commit 837d86ae21
17 changed files with 226 additions and 51 deletions
+29
View File
@@ -34,4 +34,33 @@ class ExamMemberRank extends Model
public $belongsTo = [
'member_rank' => 'GermanAirlinesVa\Schooling\Models\MemberRank',
];
public $belongsToMany = [
'exam_questions' => [
'GermanAirlinesVa\Schooling\Models\ExamMemberRankQuestion',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_id',
'otherKey' => 'exam_question_id',
],
'exam_answers' => [
'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_id',
'otherKey' => 'exam_answer_id',
],
];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('exam_member_rank_member_rank_id', function ($builder) {
$builder->where('member_rank_id', '<>', null);
});
}
}
+25
View File
@@ -33,4 +33,29 @@ class ExamMemberRankAnswer extends Model
public $belongsTo = [
'exam_question' => ['GermanAirlinesVa\Schooling\Models\ExamMemberRankQuestion', 'key' => 'exam_question_id'],
];
public $belongsToMany = [
'exam_member_ranks' => [
'GermanAirlinesVa\Schooling\Models\ExamMemberRank',
'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_member_rank_answer_member_rank_id', function ($builder) {
$builder->whereHas('exam_question', function ($query) {
$query->where('member_rank_id', '<>', null);
});
});
}
}
+27 -1
View File
@@ -32,10 +32,36 @@ class ExamMemberRankQuestion extends Model
];
public $hasMany = [
'exam_answers' => 'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer',
'exam_answers' => [
'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer',
'key' => 'exam_question_id',
],
];
public $belongsTo = [
'member_rank' => 'GermanAirlinesVa\Schooling\Models\MemberRank',
];
public $belongsToMany = [
'exam_member_ranks' => [
'GermanAirlinesVa\Schooling\Models\ExamMemberRank',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_question_id',
'otherKey' => 'exam_id',
],
];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('exam_member_rank_question_member_rank_id', function ($builder) {
$builder->where('member_rank_id', '<>', null);
});
}
}
+29
View File
@@ -34,4 +34,33 @@ class ExamTyperating extends Model
public $belongsTo = [
'typerating' => 'GermanAirlinesVa\Schooling\Models\Typerating',
];
public $belongsToMany = [
'exam_questions' => [
'GermanAirlinesVa\Schooling\Models\ExamTyperatingQuestion',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_id',
'otherKey' => 'exam_question_id',
],
'exam_answers' => [
'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_id',
'otherKey' => 'exam_answer_id',
],
];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('exam_typerating_typerating_id', function ($builder) {
$builder->where('typerating_id', '<>', null);
});
}
}
+26
View File
@@ -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);
});
});
}
}
+27 -1
View File
@@ -32,10 +32,36 @@ class ExamTyperatingQuestion extends Model
];
public $hasMany = [
'exam_answers' => 'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer',
'exam_answers' => [
'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer',
'key' => 'exam_question_id',
],
];
public $belongsTo = [
'typerating' => 'GermanAirlinesVa\Schooling\Models\Typerating',
];
public $belongsToMany = [
'exam_typeratings' => [
'GermanAirlinesVa\Schooling\Models\ExamTyperating',
'table' => 'exam_exam_answer_exam_question',
'key' => 'exam_question_id',
'otherKey' => 'exam_id',
],
];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('exam_typerating_question_typerating_id', function ($builder) {
$builder->where('typerating_id', '<>', null);
});
}
}