Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…5953 state:resolved]
  • Loading branch information...
commit de2933e1a062f0752512eb0ec60f7217f4890f8c 1 parent 296e5c3
@franckverrot franckverrot authored josevalim committed
View
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 = klass.name unless self.class.descends_from_active_record?
@dim
dim added a note

Sorry. but there is a leaner way for that, just use send(:ensure_proper_type) - https://rails.lighthouseapp.com/projects/8994/tickets/5954-patch-activerecordpersistencebecomes-does-not-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
became
end
View
9 activerecord/test/cases/persistence_test.rb
@@ -241,6 +241,15 @@ def test_update_for_record_with_only_primary_key
assert_nothing_raised { minimalistic.save }
end
+ def test_update_sti_type
+ assert_instance_of Reply, topics(:second)
+
+ topic = topics(:second).becomes(Topic)
+ assert_instance_of Topic, topic
+ topic.save!
+ assert_instance_of Topic, Topic.find(topic.id)
+ end
+
def test_delete
topic = Topic.find(1)
assert_equal topic, topic.delete, 'topic.delete did not return self'
Please sign in to comment.
Something went wrong with that request. Please try again.