diff --git a/app/models/roled/ext/base.rb b/app/models/roled/ext/base.rb index 87155848..aef88863 100644 --- a/app/models/roled/ext/base.rb +++ b/app/models/roled/ext/base.rb @@ -8,7 +8,7 @@ module Ext::Base has_many :role_whos, class_name: 'Roled::RoleWho', as: :who has_many :roles, class_name: 'Roled::Role', through: :role_whos - accepts_nested_attributes_for :role_whos + accepts_nested_attributes_for :role_whos, allow_destroy: true, reject_if: ->(attributes){ attributes.slice('role_id').blank? } has_many :role_rules, class_name: 'Roled::RoleRule', through: :roles has_many :tabs, class_name: 'Roled::Tab', through: :roles diff --git a/app/models/roled/model/cache.rb b/app/models/roled/model/cache.rb index 1bd14192..610a34ac 100644 --- a/app/models/roled/model/cache.rb +++ b/app/models/roled/model/cache.rb @@ -6,7 +6,7 @@ module Model::Cache attribute :str_role_ids, :string, index: true attribute :role_hash, :json, default: {} - has_many :cache_roles + has_many :cache_roles, dependent: :delete_all has_many :roles, through: :cache_roles after_save :sync_role_caches, if: -> { saved_change_to_str_role_ids? } @@ -18,8 +18,8 @@ def sync_role_caches end def reset_role_hash! - cache.role_hash = compute_role_hash - cache.save + self.role_hash = compute_role_hash + self.save end def compute_role_hash