public function create() { $question = new Question(); $question->setAttributes(['subject' => $this->subject, 'content' => $this->content, 'author_id' => $this->author_id]); if (($result = $question->save()) && ($result = $question->setActive())) { $tags = Tag::findAll(['name' => is_array($this->tags) ? $this->tags : explode(',', $this->tags)]); foreach ($tags as $tag) { $tagItem = new TagItem(); $tagItem->setAttributes(['target_id' => $question->id, 'target_type' => $question::TYPE]); $tag->addItem($tagItem); } } return $result ? $question : false; }
public function addItem(TagItem $item) { $item->setAttributes(['tid' => $this->id]); return $item->save(); }