From f69599478290f1e41409c4284a31e1158e39ca20 Mon Sep 17 00:00:00 2001 From: Jozef Vaclavik Date: Mon, 10 Dec 2012 01:43:39 +0100 Subject: [PATCH] Fixed Postgresql Notes search issue (integer vs string) Override accessor for "has_many :notes". Workaround for PostgreSQL: using integer ids on (text column) noteable_id in WHERE clause produces error. For more information see https://github.com/gitlabhq/gitlabhq/issues/1957 --- app/models/issue.rb | 1 + app/models/merge_request.rb | 5 ++++- app/models/snippet.rb | 1 + app/models/wiki.rb | 2 ++ app/roles/noteable.rb | 13 +++++++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/roles/noteable.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 1de9d0f9ebc..43e2abcc1b8 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -19,6 +19,7 @@ class Issue < ActiveRecord::Base include IssueCommonality include Votes + include Noteable attr_accessible :title, :assignee_id, :closed, :position, :description, :milestone_id, :label_list, :author_id_of_changes diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8039813ad1c..d0caa58e287 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -25,6 +25,7 @@ require Rails.root.join("app/roles/static_model") class MergeRequest < ActiveRecord::Base include IssueCommonality include Votes + include Noteable attr_accessible :title, :assignee_id, :closed, :target_branch, :source_branch, :milestone_id, :author_id_of_changes @@ -202,9 +203,11 @@ class MergeRequest < ActiveRecord::Base false end + # Workaround for PostgreSQL: using integer ids on (text column) noteable_id in WHERE clause produces error + # see https://github.com/gitlabhq/gitlabhq/issues/1957 def mr_and_commit_notes commit_ids = commits.map(&:id) - Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) + Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id.to_s, commit_ids: commit_ids) end # Returns the raw diff for this merge request diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 997c19bdb6b..25d22164b9c 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -15,6 +15,7 @@ class Snippet < ActiveRecord::Base include Linguist::BlobHelper + include Noteable attr_accessible :title, :content, :file_name, :expires_at diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 252a97e8cca..301c42b4495 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -13,6 +13,8 @@ # class Wiki < ActiveRecord::Base + include Noteable + attr_accessible :title, :content, :slug belongs_to :project diff --git a/app/roles/noteable.rb b/app/roles/noteable.rb new file mode 100644 index 00000000000..71feb0926ed --- /dev/null +++ b/app/roles/noteable.rb @@ -0,0 +1,13 @@ +# Contains search method as workaround for Postgresql +# Override accessor for "has_many :notes" +# Workaround for PostgreSQL: using integer ids on (text column) noteable_id in WHERE clause produces error +# see https://github.com/gitlabhq/gitlabhq/issues/1957 +module Noteable + extend ActiveSupport::Concern + + included do + def notes + Note.where(noteable_id: id.to_s, noteable_type: self.class.name) + end + end +end \ No newline at end of file -- GitLab