Merge pull request #20957 from akihiro17/find-by-issue
Fix find_by with association subquery issue
This commit is contained in:
commit
0a6c4019df
@ -1,3 +1,9 @@
|
||||
* Don't cache arguments in #find_by if they are an ActiveRecord::Relation
|
||||
|
||||
Fixes #20817
|
||||
|
||||
*Hiroaki Izu*
|
||||
|
||||
* Qualify column name inserted by `group` in calculation
|
||||
|
||||
Giving `group` an unqualified column name now works, even if the relation
|
||||
|
@ -177,7 +177,7 @@ def find_by(*args) # :nodoc:
|
||||
hash = args.first
|
||||
|
||||
return super if hash.values.any? { |v|
|
||||
v.nil? || Array === v || Hash === v
|
||||
v.nil? || Array === v || Hash === v || Relation === v
|
||||
}
|
||||
|
||||
# We can't cache Post.find_by(author: david) ...yet
|
||||
|
@ -265,6 +265,12 @@ def test_find_by_sql_with_sti_on_joined_table
|
||||
assert_equal [Account], accounts.collect(&:class).uniq
|
||||
end
|
||||
|
||||
def test_find_by_association_subquery
|
||||
author = authors(:david)
|
||||
assert_equal author.post, Post.find_by(author: Author.where(id: author))
|
||||
assert_equal author.post, Post.find_by(author_id: Author.where(id: author))
|
||||
end
|
||||
|
||||
def test_take
|
||||
assert_equal topics(:first), Topic.take
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user