diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 8cac0cd..1f1fef1 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -138,10 +138,9 @@ class Category extends \yii\db\ActiveRecord } public function getProducts() { -// return $this->hasMany(Product::className(), ['product_id' => 'product_id']) -// ->viaTable('product_category', ['category_id' => 'category_id']) -// ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); - return $this->getRelations('product_categories'); + return $this->hasMany(Product::className(), ['product_id' => 'product_id']) + ->viaTable('product_category', ['category_id' => 'category_id']); +// return $this->getRelations('product_categories'); } /** @@ -216,9 +215,8 @@ class Category extends \yii\db\ActiveRecord public function beforeDelete() { - if ( ($count = $this->getProducts()->count()) > 0) { - throw new ErrorException('С категорией "'. $this->name .'" связанно '. $count .' товаров. Удаление невозможно.'); - return false; - } + print_r($this->products); + die(); } + } -- libgit2 0.21.4