123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\models\base;
- use Yii;
- class Gallery extends \yii\db\ActiveRecord
- {
-
- public static function tableName()
- {
- return 'gallery';
- }
-
- public function rules()
- {
- return [
- [['created_at'], 'safe'],
- [['post_id'], 'integer'],
- [['name', 'description'], 'string', 'max' => 255],
- [['post_id'], 'exist', 'skipOnError' => true, 'targetClass' => News::class, 'targetAttribute' => ['post_id' => 'id']],
- ];
- }
-
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'name' => 'Name',
- 'description' => 'Description',
- 'created_at' => 'Created At',
- 'post_id' => 'Post ID',
- ];
- }
-
- public function getGalleryItems()
- {
- return $this->hasMany(GalleryItem::class, ['gallery_id' => 'id']);
- }
-
- public function getPost()
- {
- return $this->hasOne(News::class, ['id' => 'post_id']);
- }
- }
|