class ActiveRecord::Base

Workaround for github.com/citusdata/citus/issues/1236 “SELECT … FOR UPDATE is not supported for router-plannable queries”

Public Instance Methods

lock!(lock = true) click to toggle source
# File lib/activerecord-multi-tenant/with_lock.rb, line 6
def lock!(lock = true)
  if lock && persisted? && self.class.respond_to?(:scoped_by_tenant?) && MultiTenant.current_tenant_id && MultiTenant.with_lock_workaround_enabled?
    self.class.unscoped.where(id: id).update_all(id: id) # No-op UPDATE that locks the row
    reload # This is just to act similar to the default ActiveRecord approach, in case someone relies on the reload
    self
  else
    lock_orig(lock)
  end
end
Also aliased as: lock_orig
lock_orig(lock = true)
Alias for: lock!