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

Ticket #10517: include_belongs_to_with_inferred_foreign_key.patch

File include_belongs_to_with_inferred_foreign_key.patch, 1.8 kB (added by jonathan_viney, 10 months ago)
  • test/associations/eager_test.rb

    old new  
    115115    assert_equal [2], posts.collect { |p| p.id } 
    116116  end 
    117117   
     118  def test_eager_association_loading_with_belongs_to_inferred_foreign_key_from_association_name 
     119    author_favorite = AuthorFavorite.find(:first, :include => :favorite_author) 
     120    assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author } 
     121  end 
     122   
    118123  def test_eager_association_loading_with_explicit_join 
    119124    posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id') 
    120125    assert_equal 1, posts.length 
  • test/fixtures/author.rb

    old new  
    105105 
    106106class AuthorFavorite < ActiveRecord::Base 
    107107  belongs_to :author 
    108   belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id' 
     108  belongs_to :favorite_author, :class_name => "Author" 
    109109end 
  • lib/active_record/associations.rb

    old new  
    17071707                     connection.quote_table_name(aliased_table_name), 
    17081708                     reflection.klass.primary_key, 
    17091709                     connection.quote_table_name(parent.aliased_table_name), 
    1710                      options[:foreign_key] || klass.to_s.foreign_key 
     1710                     options[:foreign_key] || reflection.primary_key_name 
    17111711                    ] 
    17121712                else 
    17131713                  ""