Commit 9a527734 authored by jplang's avatar jplang

Renames column comments.comments to comments.content to please Rails 5.1 (#23630).

git-svn-id: https://svn.redmine.org/redmine/trunk@16860 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 2e71a5d7
......@@ -20,12 +20,20 @@ class Comment < ActiveRecord::Base
belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User'
validates_presence_of :commented, :author, :comments
validates_presence_of :commented, :author, :content
after_create :send_notification
safe_attributes 'comments'
def comments=(arg)
self.content = arg
end
def comments
content
end
private
def send_notification
......
......@@ -27,30 +27,6 @@ module ActiveRecord
end
end
class Relation ; undef open ; end
# Workaround for a Rails 5.1 regression that breaks queries with a condition
# on a table that has a column with the same name as the table
# (eg. comments.comments). It breaks has_many associations to these tables as well.
# https://github.com/rails/rails/commit/c6a62dc327c54baec87306f5c381e13cacc00a19
#
# Examples (without the following workaround applied):
# Comment.where(:comments => {:id => 1})
# TypeError: can't cast Hash
#
# News.first.comments.count
# TypeError: can't cast Hash
class PredicateBuilder
protected
alias :create_binds_for_hash_without_comments_fix :create_binds_for_hash
def create_binds_for_hash(attributes)
if attributes["comments"].is_a?(Hash)
return create_binds_for_hash_without_comments_fix attributes["comments"]
else
create_binds_for_hash_without_comments_fix attributes
end
end
end
end
module ActionView
......
class RenameCommentsToContent < ActiveRecord::Migration[5.1]
def change
rename_column :comments, :comments, :content
end
end
......@@ -4,7 +4,7 @@ comments_001:
commented_id: 1
id: 1
author_id: 1
comments: my first comment
content: my first comment
created_on: 2006-12-10 18:10:10 +01:00
updated_on: 2006-12-10 18:10:10 +01:00
comments_002:
......@@ -12,6 +12,6 @@ comments_002:
commented_id: 1
id: 2
author_id: 2
comments: This is an other comment
content: This is an other comment
created_on: 2006-12-10 18:12:10 +01:00
updated_on: 2006-12-10 18:12:10 +01:00
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment