diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8039813ad1ce4c2de15bf3cd39377b0e86f7735c..e9991a12f4fc3508c6dbc19be053a5ce4a83731c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -202,9 +202,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 997c19bdb6bf273af13d08f07e62073c8174afd3..e561bb5df5a91e22d1acd03b5774cad4c1056d9f 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -21,7 +21,6 @@ class Snippet < ActiveRecord::Base belongs_to :project belongs_to :author, class_name: "User" has_many :notes, as: :noteable, dependent: :destroy - delegate :name, :email, to: :author, prefix: true validates :author, presence: true @@ -35,6 +34,13 @@ class Snippet < ActiveRecord::Base scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) + # 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 + def notes + Note.where(noteable_id: id.to_s, noteable_type: self.class.name) + end + def self.content_types [ ".rb", ".py", ".pl", ".scala", ".c", ".cpp", ".java", diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 252a97e8cca647dda190cec95f3a9bbe8129181e..083baf8a9bce66f1bce86ca80969520dddb0fdec 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -18,13 +18,19 @@ class Wiki < ActiveRecord::Base belongs_to :project belongs_to :user has_many :notes, as: :noteable, dependent: :destroy - validates :content, presence: true validates :user, presence: true validates :title, presence: true, length: 1..250 before_update :set_slug + # 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 + def notes + Note.where(noteable_id: id.to_s, noteable_type: self.class.name) + end + def to_param slug end diff --git a/app/roles/issue_commonality.rb b/app/roles/issue_commonality.rb index 79831cdca67215221ab1630af87becb2f02a88c5..cde03bfd8f292b50a22cef0e7a1dfcf15ed3f7dd 100644 --- a/app/roles/issue_commonality.rb +++ b/app/roles/issue_commonality.rb @@ -32,6 +32,13 @@ module IssueCommonality prefix: true attr_accessor :author_id_of_changes + + # 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 + def notes + Note.where(noteable_id: id.to_s, noteable_type: self.class.name) + end end module ClassMethods