Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for nested :include with namespaced models.
[#260 state:committed]
  • Loading branch information
Rich Bradley authored and jeremy committed Aug 9, 2009
1 parent 9aa9bad commit 0b95a2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -1838,7 +1838,7 @@ def remove_duplicate_results!(base, records, associations)
descendant
end.flatten.compact

remove_duplicate_results!(reflection.class_name.constantize, parent_records, associations[name]) unless parent_records.empty?
remove_duplicate_results!(reflection.klass, parent_records, associations[name]) unless parent_records.empty?
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/modules_test.rb
Expand Up @@ -36,4 +36,17 @@ def test_table_name
assert_equal 'companies', MyApplication::Business::Client.table_name, 'table_name for ActiveRecord model subclass'
assert_equal 'company_contacts', MyApplication::Business::Client::Contact.table_name, 'table_name for ActiveRecord model enclosed by another ActiveRecord model'
end

def test_eager_loading_in_modules
# need to add an eager loading condition to force the eager loading model into
# the old join model, to test that. See http://dev.rubyonrails.org/ticket/9640
client_join_loaded = MyApplication::Business::Client.find(3, :include => {:firm => :account}, :conditions => 'accounts.id IS NOT NULL')
client_sequential_loaded = MyApplication::Business::Client.find(3, :include => {:firm => :account})

[client_join_loaded, client_sequential_loaded].each do |client|
assert_no_queries do
assert_not_nil(client.firm.account)
end
end
end
end
2 changes: 1 addition & 1 deletion activerecord/test/models/company_in_module.rb
Expand Up @@ -11,7 +11,7 @@ class Firm < Company
has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'

has_one :account, :dependent => :destroy
has_one :account, :class_name => 'MyApplication::Billing::Account', :dependent => :destroy
end

class Client < Company
Expand Down

0 comments on commit 0b95a2a

Please sign in to comment.