Skip to content

Commit

Permalink
Put back Relation#join method as a delegate to Array
Browse files Browse the repository at this point in the history
This is a regression 4.0 -> 4.1 fix.
In 4.1.0 Relation#join is delegated to Arel#SelectManager.
In 4.0 series it is delegated to Array#join

This patch puts back the behaviour of 4.0
  • Loading branch information
bogdan committed May 5, 2014
1 parent f200383 commit 7e20bdc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,10 @@
* Revert the behaviour of AR::Relation#join changed through 4.0 => 4.1 to 4.0

In 4.1.0 Relation#join is delegated to Arel#SelectManager.
In 4.0 series it is delegated to Array#join

*Bogdan Gusiev*

* Log nil binary column values correctly.

When an object with a binary column is updated with a nil value
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/delegation.rb
Expand Up @@ -43,7 +43,7 @@ def inherited(child_class)
:keep_if, :pop, :shift, :delete_at, :compact, :select!
].to_set # :nodoc:

delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, to: :to_a
delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join, to: :to_a

delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key,
:connection, :columns_hash, :to => :klass
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/relation/delegation_test.rb
Expand Up @@ -32,7 +32,7 @@ module DelegationWhitelistBlacklistTests
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
:map, :none?, :one?, :partition, :reject, :reverse,
:sample, :second, :sort, :sort_by, :third,
:to_ary, :to_set, :to_xml, :to_yaml
:to_ary, :to_set, :to_xml, :to_yaml, :join
]

ARRAY_DELEGATES.each do |method|
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -1677,4 +1677,8 @@ def test_merging_reorders_bind_params
merged = left.merge(right)
assert_equal post, merged.first
end

def test_relation_join_method
assert_equal 'Thank you for the welcome,Thank you again for the welcome', Post.first.comments.join(",")
end
end
4 changes: 4 additions & 0 deletions activerecord/test/models/comment.rb
Expand Up @@ -26,6 +26,10 @@ def self.all_as_method
all
end
scope :all_as_scope, -> { all }

def to_s
body
end
end

class SpecialComment < Comment
Expand Down

0 comments on commit 7e20bdc

Please sign in to comment.