提交 d5f91739 编写于 作者: P Pratik Naik

Add Relation#delete [Pratik Naik, Emilio Tagua]

上级 ea41a757
......@@ -73,7 +73,7 @@ def delete_records(records)
relation = arel_table(@reflection.options[:join_table])
relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id)))
).delete
).delete_all
end
end
......
......@@ -815,8 +815,8 @@ def update(id, attributes)
#
# # Delete multiple rows
# Todo.delete([2,3,4])
def delete(id)
delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ])
def delete(id_or_array)
arel_table.where(construct_conditions(nil, scope(:find))).delete(id_or_array)
end
# Destroy an object (or multiple objects) that has the given id, the object is instantiated first,
......@@ -2323,7 +2323,7 @@ def delete
# be made (since they can't be persisted).
def destroy
unless new_record?
self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete
self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all
end
@destroyed = true
......
......@@ -109,6 +109,10 @@ def delete_all
@relation.delete.tap { reset }
end
def delete(id_or_array)
where(@klass.primary_key => id_or_array).delete_all
end
def loaded?
@loaded
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册