提交 01777079 编写于 作者: Y Yves Senn

Merge pull request #14971 from versioncontrol/#14785

Baseclass becomes! subclass
* Baseclass becomes! subclass.
Before this change, a record which changed its STI type, could not be
updated.
Fixes #14785.
*Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
* Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
`proper_table_name` instance method on `ActiveRecord::Migration` instead.
......
......@@ -74,7 +74,14 @@ def insert(values) # :nodoc:
def _update_record(values, id, id_was) # :nodoc:
substitutes, binds = substitute_values values
um = @klass.unscoped.where(@klass.arel_table[@klass.primary_key].eq(id_was || id)).arel.compile_update(substitutes, @klass.primary_key)
scope = @klass.unscoped
if @klass.finder_needs_type_condition?
scope.unscope!(where: @klass.inheritance_column)
end
um = scope.where(@klass.arel_table[@klass.primary_key].eq(id_was || id)).arel.compile_update(substitutes, @klass.primary_key)
@klass.connection.update(
um,
......
......@@ -333,6 +333,15 @@ def test_preserve_original_sti_type
assert_equal "Reply", topic.type
end
def test_update_sti_subclass_type
assert_instance_of Topic, topics(:first)
reply = topics(:first).becomes!(Reply)
assert_instance_of Reply, reply
reply.save!
assert_instance_of Reply, Reply.find(reply.id)
end
def test_update_after_create
klass = Class.new(Topic) do
def self.name; 'Topic'; end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册