提交 3e0a60e4 编写于 作者: A Aaron Patterson

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

side of a hm:t association along with preloading.
上级 f399538f
......@@ -37,6 +37,13 @@ def setup
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')
......
class Contract < ActiveRecord::Base
belongs_to :company
belongs_to :developer
belongs_to :firm, :foreign_key => 'company_id'
before_save :hi
after_save :bye
......
......@@ -38,6 +38,8 @@ def find_least_recent
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') }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册