-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds initial implementation but still failing
- Loading branch information
1 parent
d91e62c
commit 1cb31ae
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Arel | ||
module ActiveRecordRelationExtension | ||
def delete_all(conditions = nil) | ||
tenant_id = MultiTenant.current_tenant_id | ||
tenant_key = MultiTenant.partition_key(MultiTenant.current_tenant_class) | ||
|
||
arel = eager_loading? ? apply_join_dependency.arel : build_arel | ||
arel.source.left = table | ||
|
||
group_values_arel_columns = arel_columns(group_values.uniq) | ||
having_clause_ast = having_clause.ast unless having_clause.empty? | ||
stmt = arel.compile_delete(table[primary_key], having_clause_ast, group_values_arel_columns) | ||
|
||
if tenant_id | ||
tenant_condition = table[tenant_key.downcase].eq(tenant_id) | ||
account_condition = table["account_id"].eq(tenant_id) | ||
conditions = Arel::Nodes::And.new([tenant_condition, conditions].compact) | ||
puts "conditions: #{conditions.to_sql}" | ||
puts "tenant_id: #{tenant_id}" | ||
end | ||
|
||
puts "stmt klass: #{stmt.class}" | ||
|
||
if conditions | ||
stmt.where(conditions) | ||
end | ||
|
||
puts "stmtt: #{stmt.to_sql}" | ||
klass.connection.delete(stmt, "#{klass} Delete All").tap { reset } | ||
end | ||
end | ||
end | ||
|
||
# Patch ActiveRecord::Relation with the extension module | ||
ActiveRecord::Relation.prepend(Arel::ActiveRecordRelationExtension) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters