Skip to content

Commit 859a9d5

Browse files
committed
fix user relation dependencies
1 parent 7af6f07 commit 859a9d5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

app/models/user.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class User < ActiveRecord::Base
1515

1616
validates_uniqueness_of :username, allow_nil: true, allow_blank: true
1717

18-
has_many :subscriptions
18+
has_many :subscriptions, dependent: :destroy
1919
has_many :billing_plans, through: :subscriptions
2020
def on_premium_plan?
2121
BillingPlan::PREMIUM_IDS.include?(self.selected_billing_plan_id)
@@ -24,25 +24,23 @@ def on_premium_plan?
2424
has_many :image_uploads
2525

2626
has_one :referral_code
27-
has_many :referrals, foreign_key: :referrer_id
27+
has_many :referrals, foreign_key: :referrer_id, dependent: :destroy
2828
def referrer
2929
referral = Referral.find_by(referred_id: self.id)
3030
referral.referrer unless referral.nil?
3131
end
3232

33-
has_many :votes
34-
has_many :raffle_entries
35-
36-
has_many :content_change_events
37-
38-
has_many :user_content_type_activators
33+
has_many :votes, dependent: :destroy
34+
has_many :raffle_entries, dependent: :destroy
35+
has_many :content_change_events, dependent: :destroy
36+
has_many :user_content_type_activators, dependent: :destroy
3937

4038
def contributable_universes
4139

4240
@user_contributable_universes ||= begin
4341
# todo email confirmation needs to happy for data safety / privacy (only verified emails)
4442
contributor_by_email = Contributor.where(email: self.email).pluck(:universe_id)
45-
contributor_by_user = Contributor.where(user: self).pluck(:universe_id)
43+
contributor_by_user = Contributor.where(user: self).pluck(:universe_id)
4644

4745
Universe.where(id: contributor_by_email + contributor_by_user)
4846
end
@@ -73,7 +71,7 @@ def contributable_universes
7371
end
7472

7573
# TODO: Swap this out with a has_many when we transition from a scratchpad to users having multiple documents
76-
has_one :document
74+
has_one :document, dependent: :destroy
7775

7876
after_create :initialize_stripe_customer, unless: -> { Rails.env == 'test' }
7977
after_create :initialize_referral_code

0 commit comments

Comments
 (0)