Commit e965306410539b0652c7c40b8cc031461d8b26bd

Authored by Volodymyr
1 parent 4fd34610

add tiles

common/models/Tile.php
... ... @@ -3,6 +3,7 @@
3 3 namespace common\models;
4 4  
5 5 use artbox\core\behaviors\LanguageBehavior;
  6 +use artbox\core\models\Image;
6 7 use yii\db\ActiveRecord;
7 8  
8 9 class Tile extends ActiveRecord
... ... @@ -35,12 +36,6 @@ class Tile extends ActiveRecord
35 36 ],
36 37 [
37 38 [
38   - 'image',
39   - ],
40   - 'string',
41   - ],
42   - [
43   - [
44 39 'status',
45 40 ],
46 41 'boolean',
... ... @@ -48,9 +43,25 @@ class Tile extends ActiveRecord
48 43 [
49 44 [
50 45 'sort',
  46 + 'image_id',
51 47 ],
52 48 'integer',
53 49 ],
  50 + [
  51 + ['image_id'],
  52 + 'exist',
  53 + 'skipOnError' => true,
  54 + 'targetClass' => Image::className(),
  55 + 'targetAttribute' => ['image_id' => 'id'],
  56 + ],
54 57 ];
55 58 }
  59 +
  60 + /**
  61 + * @return \yii\db\ActiveQuery
  62 + */
  63 + public function getImage()
  64 + {
  65 + return $this->hasOne(Image::className(), ['id' => 'image_id']);
  66 + }
56 67 }
57 68 \ No newline at end of file
... ...
console/migrations/m211118_133135_create_tile_table.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles the creation of table `tile`.
  7 + */
  8 +class m211118_133135_create_tile_table extends Migration
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable('tile', [
  16 + 'id' => $this->primaryKey(),
  17 + 'status' => $this->boolean(),
  18 + 'sort' => $this->smallInteger(),
  19 + 'image_id' => $this->integer(),
  20 + ]);
  21 + $this->addForeignKey(
  22 + 'fk-tile-image_id',
  23 + 'tile',
  24 + 'image_id',
  25 + 'ImageManager',
  26 + 'id',
  27 + 'CASCADE'
  28 + );
  29 + }
  30 +
  31 + /**
  32 + * @inheritdoc
  33 + */
  34 + public function down()
  35 + {
  36 + $this->dropForeignKey(
  37 + 'fk-tile-image_id',
  38 + 'tile'
  39 + );
  40 + $this->dropTable('tile');
  41 + }
  42 +}
... ...