Skip to content
This repository
Browse code

STI type is now updated when calling AR::Base.becomes on subclasses [#…

…5953 state:resolved]
  • Loading branch information...
commit de2933e1a062f0752512eb0ec60f7217f4890f8c 1 parent 296e5c3
Franck Verrot authored November 12, 2010 josevalim committed November 12, 2010
1  activerecord/lib/active_record/persistence.rb
@@ -96,6 +96,7 @@ def becomes(klass)
96 96
       became.instance_variable_set("@attributes_cache", @attributes_cache)
97 97
       became.instance_variable_set("@persisted", persisted?)
98 98
       became.instance_variable_set("@destroyed", destroyed?)
  99
+      became.type = klass.name unless self.class.descends_from_active_record?
99 100
       became
100 101
     end
101 102
 
9  activerecord/test/cases/persistence_test.rb
@@ -241,6 +241,15 @@ def test_update_for_record_with_only_primary_key
241 241
     assert_nothing_raised { minimalistic.save }
242 242
   end
243 243
 
  244
+  def test_update_sti_type
  245
+    assert_instance_of Reply, topics(:second)
  246
+
  247
+    topic = topics(:second).becomes(Topic)
  248
+    assert_instance_of Topic, topic
  249
+    topic.save!
  250
+    assert_instance_of Topic, Topic.find(topic.id)
  251
+  end
  252
+
244 253
   def test_delete
245 254
     topic = Topic.find(1)
246 255
     assert_equal topic, topic.delete, 'topic.delete did not return self'

0 notes on commit de2933e

Franck Verrot

Oh sorry man, I did not see your commit and I believe you're damn right: the patch doesnt take the inheritance_column into account. Do you wanna patch that yourself or can I do it?

(I definitely start to hate Lighthouse :/)

Please sign in to comment.
Something went wrong with that request. Please try again.