Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. =================== MySQL ====================
  2. CREATE TABLE IF NOT EXISTS `classes` (
  3. `class_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  4. `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  5. `term_id` int(11) unsigned NOT NULL,
  6. `is_core` enum('Y','N') NOT NULL DEFAULT 'N',
  7. `course_id` int(11) unsigned NOT NULL,
  8. PRIMARY KEY (`class_id`),
  9. UNIQUE KEY `term_course` (`term_id`,`course_id`),
  10. KEY `class_courseID_FK1` (`course_id`)
  11. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1663 ;
  12.  
  13.  
  14. ALTER TABLE `classes`
  15. ADD CONSTRAINT `classe_courseID_FK1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  16. ADD CONSTRAINT `classe_termID_FK1` FOREIGN KEY (`term_id`) REFERENCES `terms` (`term_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
  17.  
  18. ==================== Model ====================
  19. <?php
  20.  
  21. namespace app\models;
  22.  
  23. use Yii;
  24.  
  25. /**
  26. * This is the model class for table "classes".
  27. *
  28. * @property integer $class_id
  29. * @property string $created_date
  30. * @property integer $term_id
  31. * @property string $is_core
  32. * @property integer $course_id
  33. *
  34. * @property Categories[] $categories
  35. * @property Courses $course
  36. * @property Terms $term
  37. * @property Comments[] $comments
  38. * @property IncidentReferrals[] $incidentReferrals
  39. * @property Student2class[] $student2classes
  40. * @property Users[] $users
  41. */
  42. class Classes extends \yii\db\ActiveRecord
  43. {
  44. /**
  45. * @inheritdoc
  46. */
  47. public static function tableName()
  48. {
  49. return 'classes';
  50. }
  51.  
  52. /**
  53. * @inheritdoc
  54. */
  55. public function rules()
  56. {
  57. return [
  58. [['created_date'], 'safe'],
  59. [['term_id', 'course_id'], 'required'],
  60. [['term_id', 'course_id'], 'integer'],
  61. [['is_core'], 'string'],
  62. [['term_id', 'course_id'], 'unique', 'targetAttribute' => ['term_id', 'course_id'], 'message' => 'The combination of Term ID and Course ID has already been taken.']
  63. ];
  64. }
  65.  
  66. /**
  67. * @inheritdoc
  68. */
  69. public function attributeLabels()
  70. {
  71. return [
  72. 'class_id' => 'Class ID',
  73. 'created_date' => 'Created Date',
  74. 'term_id' => 'Term ID',
  75. 'is_core' => 'Is Core',
  76. 'course_id' => 'Course ID',
  77. ];
  78. }
  79.  
  80. /**
  81. * @return \yii\db\ActiveQuery
  82. */
  83. public function getCategories()
  84. {
  85. return $this->hasMany(Categories::className(), ['class_id' => 'class_id']);
  86. }
  87.  
  88. /**
  89. * @return \yii\db\ActiveQuery
  90. */
  91. public function getCourse()
  92. {
  93. return $this->hasOne(Courses::className(), ['course_id' => 'course_id']);
  94. }
  95.  
  96. /**
  97. * @return \yii\db\ActiveQuery
  98. */
  99. public function getTerm()
  100. {
  101. return $this->hasOne(Terms::className(), ['term_id' => 'term_id']);
  102. }
  103.  
  104. /**
  105. * @return \yii\db\ActiveQuery
  106. */
  107. public function getComments()
  108. {
  109. return $this->hasMany(Comments::className(), ['class_id' => 'class_id']);
  110. }
  111.  
  112. /**
  113. * @return \yii\db\ActiveQuery
  114. */
  115. public function getIncidentReferrals()
  116. {
  117. return $this->hasMany(IncidentReferrals::className(), ['class_id' => 'class_id']);
  118. }
  119.  
  120. /**
  121. * @return \yii\db\ActiveQuery
  122. */
  123. public function getStudent2classes()
  124. {
  125. return $this->hasMany(Student2class::className(), ['class_id' => 'class_id']);
  126. }
  127.  
  128. /**
  129. * @return \yii\db\ActiveQuery
  130. */
  131. public function getUsers()
  132. {
  133. return $this->hasMany(Users::className(), ['user_id' => 'user_id'])->viaTable('student2class', ['class_id' => 'class_id']);
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement