Class: Anoubis::Tenant::ApplicationRecord
- Inherits:
-
Core::ApplicationRecord
- Object
- Core::ApplicationRecord
- Anoubis::Tenant::ApplicationRecord
- Defined in:
- app/models/anoubis/tenant/application_record.rb
Overview
Default ApplicationRecord for Anoubis::Core library.
Class Method Summary collapse
-
.get_where(object, pid = 0) ⇒ Hash
Returns the default ActiveRecord 'where' for defined model.
Instance Method Summary collapse
-
#before_create_tenant_anoubis_model ⇒ Object
Is called before data will be created in database.
-
#before_update_tenant_anoubis_model ⇒ Object
Is called before data will be updated in database.
Class Method Details
.get_where(object, pid = 0) ⇒ Hash
Returns the default ActiveRecord 'where' for defined model.
14 15 16 17 18 19 20 |
# File 'app/models/anoubis/tenant/application_record.rb', line 14 def self.get_where(object, pid = 0) if self.has_attribute? :tenant_id return { tenant_id: object.current_user.tenant_id } else return {} end end |
Instance Method Details
#before_create_tenant_anoubis_model ⇒ Object
Is called before data will be created in database. Sets tenant according by current user
34 35 36 37 38 39 40 |
# File 'app/models/anoubis/tenant/application_record.rb', line 34 def before_create_tenant_anoubis_model begin self.tenant_id = self.current_user.tenant_id rescue end end |
#before_update_tenant_anoubis_model ⇒ Object
Is called before data will be updated in database. Prevents changing tenant
24 25 26 27 28 29 30 |
# File 'app/models/anoubis/tenant/application_record.rb', line 24 def before_update_tenant_anoubis_model begin self.tenant_id = self.tenant_id_was rescue end end |