]> source.dussan.org Git - redmine.git/commitdiff
Renames column comments.comments to comments.content to please Rails 5.1 (#23630).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Jul 2017 11:40:14 +0000 (11:40 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Jul 2017 11:40:14 +0000 (11:40 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16860 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/comment.rb
config/initializers/10-patches.rb
db/migrate/20170723112801_rename_comments_to_content.rb [new file with mode: 0644]
test/fixtures/comments.yml

index e29b574c1689be068cbac9e4eda8f60516729325..3b204412351e2b76d65f96d2eebffcdd9198cb22 100644 (file)
@@ -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
index 13efe0cb5ef72799d874b00b378812d839c97301..e98fa9cf34ce90d5a4b42d24ac6b49e251fe021f 100644 (file)
@@ -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
diff --git a/db/migrate/20170723112801_rename_comments_to_content.rb b/db/migrate/20170723112801_rename_comments_to_content.rb
new file mode 100644 (file)
index 0000000..6c01428
--- /dev/null
@@ -0,0 +1,5 @@
+class RenameCommentsToContent < ActiveRecord::Migration[5.1]
+  def change
+    rename_column :comments, :comments, :content
+  end
+end
index 8b87d5b62b5b7b9149330857222ec2305c002864..3e97b6d94fb0faad630219cba1d4c915cc000480 100644 (file)
@@ -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