Changeset 8456
- Timestamp:
- 12/21/07 01:49:01 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (2 diffs)
- trunk/activerecord/test/associations/eager_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/author.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8453 r8456 1 1 *SVN* 2 3 * Eager belongs_to :include infers the foreign key from the association name rather than the class name. #10517 [Jonathan Viney] 2 4 3 5 * SQLite: fix rename_ and remove_column for columns with unique indexes. #10576 [Brandon Keepers] trunk/activerecord/lib/active_record/associations.rb
r8305 r8456 773 773 # such as <tt>last_name, first_name DESC</tt> 774 774 # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 775 # of the associat ed class in lower-case and +_id+ suffixed. So a +Person+ class that makes a +belongs_to+ association to a776 # +Boss+ class will use +boss_id+ as the default +foreign_key+.775 # of the association with an +_id+ suffix. So a class that defines a +belongs_to :person+ association will use +person_id+ as the default +foreign_key+. 776 # Similarly, +belongs_to :favorite_person, :class_name => "Person"+ will use a foreign key of +favorite_person_id+. 777 777 # * <tt>:counter_cache</tt> - caches the number of belonging objects on the associate class through the use of +increment_counter+ 778 778 # and +decrement_counter+. The counter cache is incremented when an object of this class is created and decremented when it's … … 1708 1708 reflection.klass.primary_key, 1709 1709 connection.quote_table_name(parent.aliased_table_name), 1710 options[:foreign_key] || klass.to_s.foreign_key1710 options[:foreign_key] || reflection.primary_key_name 1711 1711 ] 1712 1712 else trunk/activerecord/test/associations/eager_test.rb
r8315 r8456 116 116 end 117 117 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 118 123 def test_eager_association_loading_with_explicit_join 119 124 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') trunk/activerecord/test/fixtures/author.rb
r8376 r8456 106 106 class AuthorFavorite < ActiveRecord::Base 107 107 belongs_to :author 108 belongs_to :favorite_author, :class_name => "Author" , :foreign_key => 'favorite_author_id'108 belongs_to :favorite_author, :class_name => "Author" 109 109 end