Module: MultiTenant::DatabaseStatements

Defined in:
lib/activerecord-multi-tenant/query_rewriter.rb

Instance Method Summary collapse

Instance Method Details

#join_to_delete(delete, *args) ⇒ Object



198
199
200
201
202
203
204
205
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 198

def join_to_delete(delete, *args)
  delete = super(delete, *args)
  model = MultiTenant.multi_tenant_model_for_table(delete.ast.left.table_name)
  if model.present?
    delete.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
  end
  delete
end

#join_to_update(update, *args) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 189

def join_to_update(update, *args)
  update = super(update, *args)
  model = MultiTenant.multi_tenant_model_for_table(update.ast.relation.table_name)
  if model.present?
    update.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
  end
  update
end