Merge pull request #310 from aboutsource/fix_deleting_memberships_on_workgroup_destroy
Fix deleting memberships on workgroup destroy
This commit is contained in:
commit
459b2826d3
3 changed files with 10 additions and 7 deletions
|
@ -1,11 +1,11 @@
|
|||
# Groups organize the User.
|
||||
# Groups organize the User.
|
||||
# A Member gets the roles from the Group
|
||||
class Group < ActiveRecord::Base
|
||||
has_many :memberships
|
||||
has_many :memberships, dependent: :destroy
|
||||
has_many :users, :through => :memberships
|
||||
|
||||
validates :name, :presence => true, :length => {:in => 1..25}
|
||||
|
||||
|
||||
attr_reader :user_tokens
|
||||
|
||||
scope :undeleted, -> { where(deleted_at: nil) }
|
||||
|
@ -14,7 +14,7 @@ class Group < ActiveRecord::Base
|
|||
def member?(user)
|
||||
memberships.find_by_user_id(user.id)
|
||||
end
|
||||
|
||||
|
||||
# Returns all NONmembers and a checks for possible multiple Ordergroup-Memberships
|
||||
def non_members
|
||||
User.natural_order.reject { |u| users.include?(u) }
|
||||
|
@ -37,5 +37,3 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
5
db/migrate/20140921104907_remove_stale_memberships.rb
Normal file
5
db/migrate/20140921104907_remove_stale_memberships.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class RemoveStaleMemberships < ActiveRecord::Migration
|
||||
def up
|
||||
Membership.where("group_id NOT IN (?)", Group.ids).delete_all
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20140521142651) do
|
||||
ActiveRecord::Schema.define(version: 20140921104907) do
|
||||
|
||||
create_table "article_categories", force: true do |t|
|
||||
t.string "name", default: "", null: false
|
||||
|
|
Loading…
Reference in a new issue