コード例 #1
0
ファイル: FiltersForm.php プロジェクト: stixlink/2Tango
 /**
  * @return GoodsQuery
  */
 public function getActiveQueryFilterGoods()
 {
     /**
      * @var GoodsQuery $query
      */
     $query = Goods::find()->alias('gds');
     if ($this->sex) {
         $query->andFilterWhere(['gds.sex_id' => $this->sex]);
     }
     if ($this->type) {
         $query->andFilterWhere(['gds.type_id' => $this->type]);
     }
     if ($this->color) {
         $query->andFilterWhere(['gds.color_id' => $this->color]);
     }
     if ($this->size) {
         $query->rightJoin(SizeGoodsRelation::tableName() . ' `sgr`', 'sgr.goods_id=gds.id');
         $query->andFilterWhere(['sgr.size_id' => $this->size]);
     }
     return $query;
 }
コード例 #2
0
ファイル: Goods.php プロジェクト: stixlink/2Tango
 public function afterSave($insert, $changedAttributes)
 {
     SizeGoodsRelation::deleteAll(['goods_id' => $this->id]);
     $values = [];
     foreach ($this->sizes as $id) {
         $values[] = [$this->id, $id];
     }
     self::getDb()->createCommand()->batchInsert(SizeGoodsRelation::tableName(), ['goods_id', 'size_id'], $values)->execute();
     parent::afterSave($insert, $changedAttributes);
 }