提交 547698e8 编写于 作者: S Santosh Wadghule

Refactor remove duplication.

上级 3132fa6b
...@@ -178,7 +178,7 @@ def delete ...@@ -178,7 +178,7 @@ def delete
# and #destroy returns +false+. # and #destroy returns +false+.
# See ActiveRecord::Callbacks for further details. # See ActiveRecord::Callbacks for further details.
def destroy def destroy
raise ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? _raise_readonly_record_error if readonly?
destroy_associations destroy_associations
self.class.connection.add_transaction_record(self) self.class.connection.add_transaction_record(self)
destroy_row if persisted? destroy_row if persisted?
...@@ -535,7 +535,7 @@ def relation_for_destroy ...@@ -535,7 +535,7 @@ def relation_for_destroy
end end
def create_or_update(*args) def create_or_update(*args)
raise ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? _raise_readonly_record_error if readonly?
result = new_record? ? _create_record : _update_record(*args) result = new_record? ? _create_record : _update_record(*args)
result != false result != false
end end
...@@ -577,5 +577,9 @@ def _raise_record_not_destroyed ...@@ -577,5 +577,9 @@ def _raise_record_not_destroyed
def belongs_to_touch_method def belongs_to_touch_method
:touch :touch
end end
def _raise_readonly_record_error
raise ReadOnlyRecord, "#{self.class} is marked as readonly"
end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册