Browse Source

Set various many-to-many models to destroy

Maarten van den Berg 8 years ago
parent
commit
9d8b22a6a9
3 changed files with 10 additions and 5 deletions
  1. 2 1
      app/models/activity.rb
  2. 4 2
      app/models/group.rb
  3. 4 2
      app/models/person.rb

+ 2 - 1
app/models/activity.rb

@@ -45,7 +45,8 @@ class Activity < ApplicationRecord
45 45
 
46 46
   belongs_to :group
47 47
 
48
-  has_many :participants
48
+  has_many :participants,
49
+    dependent: :destroy
49 50
   has_many :people, through: :participants
50 51
 
51 52
   validates :public_name, presence: true

+ 4 - 2
app/models/group.rb

@@ -6,10 +6,12 @@ class Group < ApplicationRecord
6 6
   #   @return [String]
7 7
   #     the name of the group. Must be unique across all groups.
8 8
 
9
-  has_many :members
9
+  has_many :members,
10
+    dependent: :destroy
10 11
   has_many :people, through: :members
11 12
 
12
-  has_many :activities
13
+  has_many :activities,
14
+    dependent: :destroy
13 15
 
14 16
   validates :name,
15 17
     presence: true,

+ 4 - 2
app/models/person.rb

@@ -29,8 +29,10 @@ class Person < ApplicationRecord
29 29
   #     whether or not the person has administrative rights.
30 30
 
31 31
   has_one :user
32
-  has_many :members
33
-  has_many :participants
32
+  has_many :members,
33
+    dependent: :destroy
34
+  has_many :participants,
35
+    dependent: :destroy
34 36
   has_many :groups, through: :members
35 37
   has_many :activities, through: :participants
36 38