Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

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

…5953 state:resolved]
  • Loading branch information...
1 parent 296e5c3 commit de2933e1a062f0752512eb0ec60f7217f4890f8c @franckverrot franckverrot committed with josevalim
1  activerecord/lib/active_record/persistence.rb
@@ -96,6 +96,7 @@ def becomes(klass)
became.instance_variable_set("@attributes_cache", @attributes_cache)
became.instance_variable_set("@persisted", persisted?)
became.instance_variable_set("@destroyed", destroyed?)
+ became.type = unless self.class.descends_from_active_record?
dim added a note

Sorry. but there is a leaner way for that, just use send(:ensure_proper_type) -

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 :/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
9 activerecord/test/cases/persistence_test.rb
@@ -241,6 +241,15 @@ def test_update_for_record_with_only_primary_key
assert_nothing_raised { }
+ def test_update_sti_type
+ assert_instance_of Reply, topics(:second)
+ topic = topics(:second).becomes(Topic)
+ assert_instance_of Topic, topic
+ assert_instance_of Topic, Topic.find(
+ end
def test_delete
topic = Topic.find(1)
assert_equal topic, topic.delete, 'topic.delete did not return self'

0 comments on commit de2933e

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