Changeset 4265
- Timestamp:
- 04/25/06 05:49:14 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (2 diffs)
- trunk/activerecord/test/associations_join_model_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4264 r4265 1 1 *SVN* 2 3 * Raise error when trying to add to a has_many :through association. [Rick] 4 5 @post.tags << @tag # BAD 6 @post.taggings.create(:tag => @tag) # GOOD 2 7 3 8 * Allow all calculations to take the :include option, not just COUNT (closes #4840) [Rick] trunk/activerecord/lib/active_record/associations.rb
r4264 r4265 64 64 def message 65 65 "Can not eagerly load the polymorphic association #{@reflection.name.inspect}" 66 end 67 end 68 69 class ReadOnlyAssociation < ActiveRecordError #:nodoc: 70 def initialize(reflection) 71 @reflection = reflection 72 end 73 74 def message 75 "Can not add to a has_many :through association. Try adding to #{@reflection.through_reflection.name.inspect}." 66 76 end 67 77 end trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r4169 r4265 8 8 construct_sql 9 9 end 10 11 10 12 11 def find(*args) … … 40 39 @target = [] 41 40 @loaded = false 41 end 42 43 def <<(*args) 44 raise ActiveRecord::ReadOnlyAssociation, @reflection 45 end 46 47 [:push, :concat, :create, :build].each do |method| 48 alias_method method, :<< 42 49 end 43 50 trunk/activerecord/test/associations_join_model_test.rb
r4171 r4265 356 356 def test_has_many_through_uses_correct_attributes 357 357 assert_nil posts(:thinking).tags.find_by_name("General").attributes["tag_id"] 358 end 359 360 def test_raise_error_when_adding_to_has_many_through 361 assert_raise(ActiveRecord::ReadOnlyAssociation) { posts(:thinking).tags << tags(:general) } 362 assert_raise(ActiveRecord::ReadOnlyAssociation) { posts(:thinking).tags.push tags(:general) } 363 assert_raise(ActiveRecord::ReadOnlyAssociation) { posts(:thinking).tags.concat tags(:general) } 364 assert_raise(ActiveRecord::ReadOnlyAssociation) { posts(:thinking).tags.build(:name => 'foo') } 365 assert_raise(ActiveRecord::ReadOnlyAssociation) { posts(:thinking).tags.create(:name => 'foo') } 358 366 end 359 367