Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5352 from avakhov/ar_finder_sql_uniq_ids

In AR depths use &:to_i before :uniq to process mixed arrays likes ["1", 1] correct
  • Loading branch information...
commit 74d5d9a3348be724f1b23c36d6446657cabae1fa 2 parents 225eff9 + 48a7df9
@josevalim josevalim authored
View
2  activerecord/lib/active_record/associations/collection_association.rb
@@ -544,7 +544,7 @@ def include_in_memory?(record)
# If using a custom finder_sql, #find scans the entire collection.
def find_by_scan(*args)
expects_array = args.first.kind_of?(Array)
- ids = args.flatten.compact.uniq.map { |arg| arg.to_i }
+ ids = args.flatten.compact.map{ |arg| arg.to_i }.uniq
if ids.size == 1
id = ids.first
View
7 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -378,6 +378,13 @@ def test_finding_using_sql
assert_equal 1, Firm.find(:first, :order => "id").clients_using_sql.size
end
+ def test_finding_using_sql_take_into_account_only_uniq_ids
+ firm = Firm.find(:first, :order => "id")
+ client = firm.clients_using_sql.first
+ assert_equal client, firm.clients_using_sql.find(client.id, client.id)
+ assert_equal client, firm.clients_using_sql.find(client.id, client.id.to_s)
+ end
+
def test_counting_using_sql
assert_equal 1, Firm.find(:first, :order => "id").clients_using_counter_sql.size
assert Firm.find(:first, :order => "id").clients_using_counter_sql.any?
Please sign in to comment.
Something went wrong with that request. Please try again.