GermanAirlinesVA-Schooling/models/ExamMemberRankAnswer.php

62 lines
1.4 KiB
PHP

<?php namespace GermanAirlinesVa\Schooling\Models;
use Model;
/**
* Model
*/
class ExamMemberRankAnswer extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'exam_answers';
protected $connection = 'germanairlinesva_schooling';
/**
* @var array Validation rules
*/
public $rules = [
'exam_question' => 'required',
'text' => 'required',
'is_correct' => 'required',
];
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);
});
});
}
}