mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix include? on has_many collections with finder_sql to fall back to Array include? rather than try to use SQL.
[#18 state:resolved]
This commit is contained in:
parent
ae51013c3f
commit
b6aa0e13b4
2 changed files with 12 additions and 0 deletions
|
@ -214,6 +214,7 @@ module ActiveRecord
|
|||
|
||||
def include?(record)
|
||||
return false unless record.is_a?(@reflection.klass)
|
||||
load_target if @reflection.options[:finder_sql] && !loaded?
|
||||
return @target.include?(record) if loaded?
|
||||
exists?(record)
|
||||
end
|
||||
|
|
|
@ -832,6 +832,17 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|||
assert ! firm.clients.loaded?
|
||||
end
|
||||
|
||||
def test_include_loads_collection_if_target_uses_finder_sql
|
||||
firm = companies(:first_firm)
|
||||
client = firm.clients_using_sql.first
|
||||
|
||||
firm.reload
|
||||
assert ! firm.clients_using_sql.loaded?
|
||||
assert firm.clients_using_sql.include?(client)
|
||||
assert firm.clients_using_sql.loaded?
|
||||
end
|
||||
|
||||
|
||||
def test_include_returns_false_for_non_matching_record_to_verify_scoping
|
||||
firm = companies(:first_firm)
|
||||
client = Client.create!(:name => 'Not Associated')
|
||||
|
|
Loading…
Reference in a new issue