alexbevi / redmine_knowledgebase

A knowledgebase plugin for Redmine
452 stars 199 forks source link

Unknown column 'taggings.context' in 'where clause': #334

Closed bluenevus closed 8 years ago

bluenevus commented 8 years ago

ActiveRecord::StatementInvalid (Mysql2::Error: Unknown column 'taggings.context' in 'where clause': SELECT tags.*, taggings.tags_count AS count FROM tags JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM taggings INNER JOIN kb_articles ON kb_articles.id = taggings.taggable_id WHERE (taggings.taggable_type = 'KbArticle' AND taggings.context = 'tags') AND (taggings.taggable_id IN (NULL)) GROUP BY taggings.tag_id HAVING COUNT(taggings.tag_id) > 0) AS taggings ON taggings.tag_id = tags.id): plugins/redmine_knowledgebase/app/controllers/articles_controller.rb:33:in index' lib/redmine/sudo_mode.rb:63:insudo_mode'

redmine 3.3

bluenevus commented 8 years ago

nevermind. added the column manually and it woked

djfml commented 7 years ago

Mysql2::Error: Unknown column 'taggings.context' in 'where clause': SELECTtags.* FROMtagsINNER JOINtaggingsONtags.id=taggings.tag_idWHEREtaggings.taggable_idIS NULL ANDtaggings.taggable_type= 'KbArticle' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)

how to resolve it ? Is it the same problem?

baku2san commented 7 years ago

Right after installed, I faced a similar error. It may be caused by that there was no tag. Thus, I modified it and it was fixed.

The error was the followings:


ActiveRecord::StatementInvalid (TinyTds::Error: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.: EXEC sp_executesql N'SELECT tags.*, taggings.tags_count AS count FROM [tags] JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM [taggings] INNER JOIN kb_articles ON kb_articles.id = taggings.taggable_id WHERE (taggings.taggable_type = N''KbArticle'' AND taggings.context = N''tags'') AND (taggings.taggable_id IN(SELECT kb_articles.id FROM [kb_articles] WHERE [kb_articles].[category_id] = 5  ORDER BY title asc)) GROUP BY taggings.tag_id HAVING COUNT(taggings.tag_id) > 0) AS taggings ON taggings.tag_id = tags.id'):
  plugins/redmine_knowledgebase/app/controllers/categories_controller.rb:27:in `show'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'
[categories_controller.rb.diff.txt](https://github.com/alexbevi/redmine_knowledgebase/files/829363/categories_controller.rb.diff.txt)

The patch is the followings:


diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 0330f57..c2c823c 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -16,15 +16,15 @@ class CategoriesController < ApplicationController
   def show

     @articles = @category.articles.order("#{sort_column} #{sort_direction}")
+    @categories = @project.categories.where(:parent_id => nil)

     if params[:tag]
       @tag = params[:tag]
       @articles = @articles.tagged_with(@tag)
+      @tags = @articles.tag_counts.sort { |a, b| a.name.downcase <=> b.name.downcase }
     end

-    @categories = @project.categories.where(:parent_id => nil)

-    @tags = @articles.tag_counts.sort { |a, b| a.name.downcase <=> b.name.downcase }

     respond_to do |format|
       format.html { render :template => 'categories/show', :layout => !request.xhr? }