mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Show proper error message when a non-relation object is passed to AR::Relation#or
- Previously it used to show error message <"undefined method `limit_value' for {:title=>\"Rails\"}:Hash"> - Now it shows following error message. >> Post.where.not(name: 'DHH').or(name: 'Tenderlove') ArgumentError: You have passed Hash object to #or. Pass an ActiveRecord::Relation object instead. - Fixes #23714.
This commit is contained in:
parent
bb4a85da10
commit
e254665ac0
2 changed files with 10 additions and 0 deletions
|
@ -655,6 +655,10 @@ module ActiveRecord
|
|||
# # SELECT `posts`.* FROM `posts` WHERE (('id = 1' OR 'author_id = 3'))
|
||||
#
|
||||
def or(other)
|
||||
unless other.is_a? Relation
|
||||
raise ArgumentError, "You have passed #{other.class.name} object to #or. Pass an ActiveRecord::Relation object instead."
|
||||
end
|
||||
|
||||
spawn.or!(other)
|
||||
end
|
||||
|
||||
|
|
|
@ -82,5 +82,11 @@ module ActiveRecord
|
|||
assert_equal p.loaded?, true
|
||||
assert_equal expected, p.or(Post.where('id = 2')).to_a
|
||||
end
|
||||
|
||||
def test_or_with_non_relation_object_raises_error
|
||||
assert_raises ArgumentError do
|
||||
Post.where(id: [1, 2, 3]).or(title: 'Rails')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue