Gallery.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\models\base;
  3. use Yii;
  4. /**
  5. * This is the model class for table "gallery".
  6. *
  7. * @property int $id
  8. * @property string|null $name
  9. * @property string|null $description
  10. * @property string|null $created_at
  11. * @property int|null $post_id
  12. *
  13. * @property GalleryItem[] $galleryItems
  14. * @property News $post
  15. */
  16. class Gallery extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return 'gallery';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['created_at'], 'safe'],
  32. [['post_id'], 'integer'],
  33. [['name', 'description'], 'string', 'max' => 255],
  34. [['post_id'], 'exist', 'skipOnError' => true, 'targetClass' => News::class, 'targetAttribute' => ['post_id' => 'id']],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'name' => 'Name',
  45. 'description' => 'Description',
  46. 'created_at' => 'Created At',
  47. 'post_id' => 'Post ID',
  48. ];
  49. }
  50. /**
  51. * Gets query for [[GalleryItems]].
  52. *
  53. * @return \yii\db\ActiveQuery
  54. */
  55. public function getGalleryItems()
  56. {
  57. return $this->hasMany(GalleryItem::class, ['gallery_id' => 'id']);
  58. }
  59. /**
  60. * Gets query for [[Post]].
  61. *
  62. * @return \yii\db\ActiveQuery
  63. */
  64. public function getPost()
  65. {
  66. return $this->hasOne(News::class, ['id' => 'post_id']);
  67. }
  68. }