Permalink
Browse files

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

side of a hm:t association along with preloading.
  • Loading branch information...
1 parent f399538 commit 3e0a60e4e2316ee696bdcf1c115582f8f450ad07 @tenderlove tenderlove committed Sep 27, 2013
@@ -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')
@@ -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
@@ -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') }

0 comments on commit 3e0a60e

Please sign in to comment.