Add before_destroy :cancel to precent role destroy.Change Conference-Role association to have dependent: :destroy_all
This commit is contained in:
parent
2df6d1039f
commit
48b48e88ac
2 changed files with 10 additions and 2 deletions
|
|
@ -4,7 +4,8 @@ class Conference < ActiveRecord::Base
|
|||
require 'uri'
|
||||
serialize :events_per_week, Hash
|
||||
# Needed to call 'Conference.with_role' in /models/ability.rb
|
||||
resourcify
|
||||
# Dependent destroy will fail as roles#destroy will be cancelled,hence delete_all
|
||||
resourcify :roles, dependent: :delete_all
|
||||
|
||||
default_scope { order('start_date DESC') }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
class Role < ActiveRecord::Base
|
||||
belongs_to :resource, polymorphic: true
|
||||
has_and_belongs_to_many :users, join_table: :users_roles
|
||||
|
||||
before_destroy :cancel
|
||||
scopify
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
validates :name, uniqueness: { scope: :resource }
|
||||
|
||||
private
|
||||
|
||||
# Needed to ensure that removing all user from role doesn't remove role.
|
||||
def cancel
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue