Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    370370    assert_equal 10, firm.clients_with_interpolated_conditions.first.rating 
    371371  end 
    372372 
     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 
    373382  def test_assignment_before_child_saved 
    374383    firm = Firm.find(1) 
    375384    firm.account = a = Account.new("credit_limit" => 1000) 
  • activerecord/test/fixtures/post.rb

    old new  
    1919 
    2020  has_and_belongs_to_many :categories 
    2121  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' 
    2223 
    2324  has_many :taggings, :as => :taggable 
    2425  has_many :tags, :through => :taggings, :include => :tagging do 
  • activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb

    old new  
    136136        end 
    137137         
    138138        def construct_sql 
    139           interpolate_sql_options!(@reflection.options, :finder_sql) 
    140  
    141139          if @reflection.options[:finder_sql] 
    142             @finder_sql = @reflection.options[:finder_sql] 
     140            @finder_sql = interpolate_sql(@reflection.options[:finder_sql]) 
    143141          else 
    144142            @finder_sql = "#{@reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{@owner.quoted_id} " 
    145143            @finder_sql << " AND (#{conditions})" if conditions