Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =================== MySQL ====================
- CREATE TABLE IF NOT EXISTS `classes` (
- `class_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
- `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `term_id` int(11) unsigned NOT NULL,
- `is_core` enum('Y','N') NOT NULL DEFAULT 'N',
- `course_id` int(11) unsigned NOT NULL,
- PRIMARY KEY (`class_id`),
- UNIQUE KEY `term_course` (`term_id`,`course_id`),
- KEY `class_courseID_FK1` (`course_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1663 ;
- ALTER TABLE `classes`
- ADD CONSTRAINT `classe_courseID_FK1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`) ON DELETE CASCADE ON UPDATE NO ACTION,
- ADD CONSTRAINT `classe_termID_FK1` FOREIGN KEY (`term_id`) REFERENCES `terms` (`term_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
- ==================== Model ====================
- <?php
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "classes".
- *
- * @property integer $class_id
- * @property string $created_date
- * @property integer $term_id
- * @property string $is_core
- * @property integer $course_id
- *
- * @property Categories[] $categories
- * @property Courses $course
- * @property Terms $term
- * @property Comments[] $comments
- * @property IncidentReferrals[] $incidentReferrals
- * @property Student2class[] $student2classes
- * @property Users[] $users
- */
- class Classes extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'classes';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['created_date'], 'safe'],
- [['term_id', 'course_id'], 'required'],
- [['term_id', 'course_id'], 'integer'],
- [['is_core'], 'string'],
- [['term_id', 'course_id'], 'unique', 'targetAttribute' => ['term_id', 'course_id'], 'message' => 'The combination of Term ID and Course ID has already been taken.']
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'class_id' => 'Class ID',
- 'created_date' => 'Created Date',
- 'term_id' => 'Term ID',
- 'is_core' => 'Is Core',
- 'course_id' => 'Course ID',
- ];
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getCategories()
- {
- return $this->hasMany(Categories::className(), ['class_id' => 'class_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getCourse()
- {
- return $this->hasOne(Courses::className(), ['course_id' => 'course_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getTerm()
- {
- return $this->hasOne(Terms::className(), ['term_id' => 'term_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getComments()
- {
- return $this->hasMany(Comments::className(), ['class_id' => 'class_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getIncidentReferrals()
- {
- return $this->hasMany(IncidentReferrals::className(), ['class_id' => 'class_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getStudent2classes()
- {
- return $this->hasMany(Student2class::className(), ['class_id' => 'class_id']);
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getUsers()
- {
- return $this->hasMany(Users::className(), ['user_id' => 'user_id'])->viaTable('student2class', ['class_id' => 'class_id']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement