Changeset 7188
- Timestamp:
- 07/16/07 20:21:36 (10 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/reflection.rb (modified) (1 diff)
- trunk/activerecord/test/associations_test.rb (modified) (1 diff)
- trunk/activerecord/test/reflection_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r7187 r7188 1 1 *SVN* 2 3 * Change belongs_to so that the foreign_key assumption is taken from the association name, not the class name. Closes #8992 [hasmanyjosh] 4 5 OLD 6 belongs_to :visitor, :class_name => 'User' # => inferred foreign_key is user_id 7 8 NEW 9 belongs_to :visitor, :class_name => 'User' # => inferred foreign_key is visitor_id 2 10 3 11 * Remove spurious tests from deprecated_associations_test, most of these aren't deprecated, and are duplicated in associations_test. Closes #8987 [lifofifo] trunk/activerecord/lib/active_record/associations.rb
r7137 r7188 800 800 # belongs_to :attachable, :polymorphic => true 801 801 def belongs_to(association_id, options = {}) 802 if options.include?(:class_name) && !options.include?(:foreign_key)803 ::ActiveSupport::Deprecation.warn(804 "The inferred foreign_key name will change in Rails 2.0 to use the association name instead of its class name when they differ. When using :class_name in belongs_to, use the :foreign_key option to explicitly set the key name to avoid problems in the transition.",805 caller)806 end807 808 802 reflection = create_belongs_to_reflection(association_id, options) 809 803 trunk/activerecord/lib/active_record/reflection.rb
r6408 r7188 208 208 def derive_primary_key_name 209 209 if macro == :belongs_to 210 class_name.foreign_key210 "#{name}_id" 211 211 elsif options[:as] 212 212 "#{options[:as]}_id" trunk/activerecord/test/associations_test.rb
r7137 r7188 410 410 end 411 411 412 def test_deprecated_inferred_foreign_key413 assert_not_deprecated { Company.belongs_to :firm }414 assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" }415 assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" }416 assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" }417 end418 419 412 end 420 413 trunk/activerecord/test/reflection_test.rb
r5923 r7188 112 112 end 113 113 114 def test_belongs_to_inferred_foreign_key_from_assoc_name 115 Company.belongs_to :foo 116 assert_equal "foo_id", Company.reflect_on_association(:foo).primary_key_name 117 Company.belongs_to :bar, :class_name => "Xyzzy" 118 assert_equal "bar_id", Company.reflect_on_association(:bar).primary_key_name 119 Company.belongs_to :baz, :class_name => "Xyzzy", :foreign_key => "xyzzy_id" 120 assert_equal "xyzzy_id", Company.reflect_on_association(:baz).primary_key_name 121 end 122 114 123 def test_association_reflection_in_modules 115 124 assert_reflection MyApplication::Business::Firm,