1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

adding a test to demonstrate how to use STI subclasses on the far right

side of a hm:t association along with preloading.
This commit is contained in:
Aaron Patterson 2013-09-27 16:56:49 -07:00
parent f399538f99
commit 3e0a60e4e2
3 changed files with 10 additions and 0 deletions

View file

@ -37,6 +37,13 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
Reader.create :person_id => 0, :post_id => 0
end
def test_preload_sti_rhs_class
developers = Developer.includes(:firms).all.to_a
assert_no_queries do
developers.each { |d| d.firms }
end
end
def test_preload_sti_middle_relation
club = Club.create!(name: 'Aaron cool banana club')
member1 = Member.create!(name: 'Aaron')

View file

@ -1,6 +1,7 @@
class Contract < ActiveRecord::Base
belongs_to :company
belongs_to :developer
belongs_to :firm, :foreign_key => 'company_id'
before_save :hi
after_save :bye

View file

@ -38,6 +38,8 @@ class Developer < ActiveRecord::Base
has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
has_many :audit_logs
has_many :contracts
has_many :firms, :through => :contracts, :source => :firm
scope :jamises, -> { where(:name => 'Jamis') }