mirror of
https://github.com/redmine/redmine.git
synced 2025-10-26 07:46:17 +01:00
Renames column comments.comments to comments.content to please Rails 5.1 (#23630).
git-svn-id: http://svn.redmine.org/redmine/trunk@16860 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -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
|
||||
|
||||
5
db/migrate/20170723112801_rename_comments_to_content.rb
Normal file
5
db/migrate/20170723112801_rename_comments_to_content.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class RenameCommentsToContent < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
rename_column :comments, :comments, :content
|
||||
end
|
||||
end
|
||||
4
test/fixtures/comments.yml
vendored
4
test/fixtures/comments.yml
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user