Ticket #7576: has_and_belongs_to_many_interpolation.diff
| File has_and_belongs_to_many_interpolation.diff, 2.5 kB (added by alexkwolfe, 2 years ago) |
|---|
-
activerecord/test/associations_test.rb
old new 370 370 assert_equal 10, firm.clients_with_interpolated_conditions.first.rating 371 371 end 372 372 373 def test_finder_sql_interpolated_for_each_instance_on_has_and_belongs_to_many 374 first_post = Post.find(:first) 375 first_post.categories.create(:name => 'Interpolated First') 376 last_post = Post.find(:all).last 377 last_post.categories.create(:name => 'Interpolated Last') 378 assert_not_equal first_post, last_post 379 assert_not_equal first_post.categories_with_interpolated_finder_sql, last_post.categories_with_interpolated_finder_sql 380 end 381 373 382 def test_assignment_before_child_saved 374 383 firm = Firm.find(1) 375 384 firm.account = a = Account.new("credit_limit" => 1000) -
activerecord/test/fixtures/post.rb
old new 19 19 20 20 has_and_belongs_to_many :categories 21 21 has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id' 22 has_and_belongs_to_many :categories_with_interpolated_finder_sql, :class_name => 'Category', :finder_sql => 'select categories.* from categories_posts, categories where post_id=#{id} and categories.id=category_id' 22 23 23 24 has_many :taggings, :as => :taggable 24 25 has_many :tags, :through => :taggings, :include => :tagging do -
activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
old new 136 136 end 137 137 138 138 def construct_sql 139 interpolate_sql_options!(@reflection.options, :finder_sql)140 141 139 if @reflection.options[:finder_sql] 142 @finder_sql = @reflection.options[:finder_sql]140 @finder_sql = interpolate_sql(@reflection.options[:finder_sql]) 143 141 else 144 142 @finder_sql = "#{@reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{@owner.quoted_id} " 145 143 @finder_sql << " AND (#{conditions})" if conditions