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:
parent
f399538f99
commit
3e0a60e4e2
3 changed files with 10 additions and 0 deletions
|
@ -37,6 +37,13 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
Reader.create :person_id => 0, :post_id => 0
|
Reader.create :person_id => 0, :post_id => 0
|
||||||
end
|
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
|
def test_preload_sti_middle_relation
|
||||||
club = Club.create!(name: 'Aaron cool banana club')
|
club = Club.create!(name: 'Aaron cool banana club')
|
||||||
member1 = Member.create!(name: 'Aaron')
|
member1 = Member.create!(name: 'Aaron')
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Contract < ActiveRecord::Base
|
class Contract < ActiveRecord::Base
|
||||||
belongs_to :company
|
belongs_to :company
|
||||||
belongs_to :developer
|
belongs_to :developer
|
||||||
|
belongs_to :firm, :foreign_key => 'company_id'
|
||||||
|
|
||||||
before_save :hi
|
before_save :hi
|
||||||
after_save :bye
|
after_save :bye
|
||||||
|
|
|
@ -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_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
|
||||||
|
|
||||||
has_many :audit_logs
|
has_many :audit_logs
|
||||||
|
has_many :contracts
|
||||||
|
has_many :firms, :through => :contracts, :source => :firm
|
||||||
|
|
||||||
scope :jamises, -> { where(:name => 'Jamis') }
|
scope :jamises, -> { where(:name => 'Jamis') }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue