Class: Anoubis::Tenant::ApplicationRecord

Inherits:
Core::ApplicationRecord show all
Defined in:
app/models/anoubis/tenant/application_record.rb

Overview

Default ApplicationRecord for Anoubis::Core library.

Direct Known Subclasses

Menu, TenantSystem, User, UserGroup

Instance Attribute Summary

Attributes inherited from Core::ApplicationRecord

#can_delete, #can_edit, #can_new, #created_at, #current_user, #need_refresh, #redis, #sys_title, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::ApplicationRecord

#after_initialize_core_anubis_model, #can_destroy?, #current_locale, #current_locale=, #default_locale, #get_locale, #get_locale_field, #is_field_localized, #new_uuid, redis, redis_prefix, #redis_prefix, #set_locale_field

Class Method Details

.get_where(object, pid = 0) ⇒ Hash

Returns the default ActiveRecord ‘where’ for defined model.

Parameters:

  • object (ApplicationController)

    pointer to used Application controller

  • pid (Integer) (defaults to: 0)

    parent model id if present (default: 0). Variable doesn’t necessary

Returns:

  • (Hash)

    ActiveRecord ‘where’ definition



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_modelObject

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_modelObject

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