/** * Returns the foreign key name of the tag-model relation for tag_id. You can * override this method in order to provide a custom foreign key name. * * @return string */ protected function getForeignKeyRelationTag() { return 'FK_' . Inflector::camelize(Tag::relationTableName()) . '_TagId'; }
/** * * @return \jlorente\tagable\db\TagQuery */ public function getTags() { return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable(Tag::relationTableName(), ['model_id' => 'id'], function ($query) { $query->andWhere([Tag::relationTableName() . '.association_type' => $this->getTagAssociationType()]); }); }
/** * Filters the tags by the association type. * * @param $type string * @return $this */ public function filterType($type) { return $this->innerJoin(Tag::relationTableName(), Tag::relationTableName() . '.`tag_id` = ' . Tag::tableName() . '.`id`')->andWhere([Tag::relationTableName() . '.`association_type`' => $type])->groupBy([Tag::tableName() . '.`id`']); }