Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     TagPost::deleteAll(['post_id' => $this->id]);
     if (is_array($this->tags) && !empty($this->tags)) {
         $values = [];
         foreach ($this->tags as $id) {
             $values[] = [$this->id, $id];
         }
         self::getDb()->createCommand()->batchInsert(TagPost::tableName(), ['post_id', 'tag_id'], $values)->execute();
     }
     parent::afterSave($insert, $changedAttributes);
 }
Exemplo n.º 2
0
 /**
  * return post that relatives to tag
  * @return ActiveQuery
  */
 public function getTagPosts()
 {
     return $this->hasMany(TagPost::className(), ['tag_id' => 'id']);
 }