public function actionAdd($ingredientId) { // less queries here $postType = Posts::TYPE_USER_INGREDIENTS; $post = Posts::find()->where(['and', ['PostType' => $postType], ['UserID' => Yii::$app->user->getId()]])->one(); if (!$post) { $post = new Posts(); $post->PostType = $postType; $post->UserID = Yii::$app->user->getId(); $post->save(); } $ingredient = Tags::findOne($ingredientId); $post->link('tags', $ingredient); }
public function getTags() { return $this->hasMany(Tags::className(), ['id' => 'tag_id'])->viaTable('page_tags_rel', ['page_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getTags() { return $this->hasMany(Tags::className(), ['TagID' => 'TagID'])->viaTable('PostTags', ['PostID' => 'PostID']); }
public function getAvaliableIngredients() { $tags = Tags::find()->where(['TypeID' => Tags::TYPE_COCKTAIL_INGREDIENT])->all(); return $tags; }