Favourite.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace common\models;
  3. use yii\behaviors\TimestampBehavior;
  4. /**
  5. * This is the model class for table "pop_favourite".
  6. *
  7. * @property integer $id
  8. * @property integer $user_id
  9. * @property integer $article_id
  10. * @property integer $created_at
  11. */
  12. class Favourite extends \yii\db\ActiveRecord
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public static function tableName()
  18. {
  19. return '{{%favourite}}';
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public function rules()
  25. {
  26. return [
  27. [['user_id', 'article_id'], 'required'],
  28. [['user_id', 'article_id'], 'integer']
  29. ];
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function attributeLabels()
  35. {
  36. return [
  37. 'id' => 'ID',
  38. 'user_id' => '用户',
  39. 'article_id' => '文章',
  40. 'created_at' => '收藏时间',
  41. ];
  42. }
  43. public function behaviors()
  44. {
  45. return [
  46. [
  47. 'class' => TimestampBehavior::className(),
  48. 'updatedAtAttribute' => false
  49. ],
  50. ];
  51. }
  52. public function getArticle()
  53. {
  54. return $this->hasOne(Article::className(), ['id' => 'article_id']);
  55. }
  56. }