Blame view

common/models/ProductToProject.php 3.22 KB
cc658b4c   Yarik   Big commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  <?php
      
      namespace common\models;
      
      use common\modules\product\models\Product;
      use common\modules\product\models\ProductVariant;
      
      /**
       * This is the model class for table "product_to_project".
       * @property integer        $product_to_project_id
       * @property integer        $product_variant_id
       * @property integer        $project_id
       * @property ProductVariant $productVariant
       * @property Project        $project
       * @property Product        $product
       */
      class ProductToProject extends \yii\db\ActiveRecord
      {
          
          public $product_id;
          
          /**
           * @inheritdoc
           */
          public static function tableName()
          {
              return 'product_to_project';
          }
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'product_variant_id',
                          'project_id',
                          'product_id'
                      ],
                      'required',
                  ],
                  [
                      [
                          'product_variant_id',
                          'product_id',
                      ],
                      'integer',
                  ],
                  [
                      [
                          'product_variant_id',
                          'project_id',
                      ],
                      'unique',
                      'targetAttribute' => [
                          'product_variant_id',
                          'project_id',
                      ],
                      'message'         => 'The combination of Product Variant ID and Project ID has already been taken.',
                  ],
                  [
                      [ 'product_variant_id' ],
                      'exist',
                      'skipOnError'     => true,
                      'targetClass'     => ProductVariant::className(),
                      'targetAttribute' => [ 'product_variant_id' => 'product_variant_id' ],
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
                  'product_to_project_id' => 'Product To Project ID',
                  'product_variant_id'    => 'Product Variant ID',
                  'project_id'            => 'Project ID',
                  'product_id'            => 'Product',
              ];
          }
          
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getProductVariant()
          {
              return $this->hasOne(ProductVariant::className(), [ 'product_variant_id' => 'product_variant_id' ]);
          }
          
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getProject()
          {
              return $this->hasOne(Project::className(), [ 'project_id' => 'project_id' ]);
          }
          
          public function getProduct()
          {
              return $this->hasOne(Product::className(), [
                  'product_id' => 'product_id',
              ])
                          ->viaTable('product_variant', [ 'product_variant_id' => 'product_variant_id' ]);
          }
      }