Skip to content

Commit

Permalink
Merge pull request #1718 from guilleiguaran/5-1-upgrade-models
Browse files Browse the repository at this point in the history
Associations should be defined before of being used in `:through`
  • Loading branch information
hsbt authored May 7, 2018
2 parents 88ced40 + 4f87c66 commit 9a27e82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/rubygem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class Rubygem < ApplicationRecord
include Patterns
include RubygemSearchable

has_many :owners, through: :ownerships, source: :user
has_many :ownerships, dependent: :destroy
has_many :subscribers, through: :subscriptions, source: :user
has_many :owners, through: :ownerships, source: :user
has_many :subscriptions, dependent: :destroy
has_many :subscribers, through: :subscriptions, source: :user
has_many :versions, dependent: :destroy, validate: false
has_one :latest_version, -> { where(latest: true).order(:position) }, class_name: "Version"
has_many :web_hooks, dependent: :destroy
Expand Down
5 changes: 3 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class User < ApplicationRecord
].freeze

before_destroy :yank_gems

has_many :ownerships, dependent: :destroy
has_many :rubygems, through: :ownerships

has_many :subscriptions, dependent: :destroy
has_many :subscribed_gems, -> { order("name ASC") }, through: :subscriptions, source: :rubygem

has_many :deletions
has_many :ownerships, dependent: :destroy
has_many :subscriptions, dependent: :destroy
has_many :web_hooks, dependent: :destroy

after_validation :set_unconfirmed_email, if: :email_changed?, on: :update
Expand Down

0 comments on commit 9a27e82

Please sign in to comment.