OSDN Git Service

Добавлен тест модели типов.
[invent/invent.git] / models / Types.php
index be5e194..dce3125 100644 (file)
@@ -34,7 +34,9 @@ class Types extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['name'], 'string', 'max' => 20],
+            [[ 'id' ], 'integer' ],
+            [[ 'name' ], 'string', 'max' => 100, ],
+            [[ 'name' ], 'required' ],
         ];
     }
 
@@ -57,8 +59,13 @@ class Types extends \yii\db\ActiveRecord
      *
      * @return \yii\db\ActiveQuery
      */
+    public function getModels()
+    {
+        return $this->hasMany(Models::className(), [ 'type_id' => 'id' ]);
+    }
+
     public function getItems()
     {
-        return $this->hasMany(Items::className(), [ 'type_id' => 'id' ]);
+        return $this->getModels()->select(Items::tableName() . '.*')->joinWith('items');
     }
 }