Module: MultiTenant::DatabaseStatements

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

Instance Method Summary collapse

Instance Method Details

#delete(arel, name = nil, binds = []) ⇒ Object



270
271
272
273
274
275
276
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 270

def delete(arel, name = nil, binds = [])
  model = MultiTenant.multi_tenant_model_for_arel(arel)
  if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
    arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
  end
  super(arel, name, binds)
end

#join_to_delete(delete, *args) ⇒ Object



253
254
255
256
257
258
259
260
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 253

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

#join_to_update(update, *args) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 244

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

#update(arel, name = nil, binds = []) ⇒ Object



262
263
264
265
266
267
268
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 262

def update(arel, name = nil, binds = [])
  model = MultiTenant.multi_tenant_model_for_arel(arel)
  if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
    arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
  end
  super(arel, name, binds)
end