* Favoring delete_all on user relationships Prior to this commit, several of the user's "has_many" were marked as `depenedent: :destroy`. In the case of :destroy, ActiveRecord instantiates each object and then runs destroy. Whereas in the case of :delete, ActiveRecord issues a SQL command to delete the related files. It is often "safer" to use :destroy, as it guarantees that you'll instantiate the record and run it's callbacks. But sometimes you have to go with the speed of SQL. And while not directly related to #15424 it is representative of our callback ecosystem creating some unexpected computational loads. Related to #15442 and #15424 * Noting models that user no longer cascade destroys
10 lines
459 B
Ruby
10 lines
459 B
Ruby
# @note When we destroy the related user, it's using dependent:
|
|
# :delete for the relationship. That means no before/after
|
|
# destroy callbacks will be called on this object.
|
|
class PodcastOwnership < ApplicationRecord
|
|
belongs_to :owner, class_name: "User", foreign_key: :user_id, inverse_of: :podcasts_owned
|
|
belongs_to :podcast
|
|
|
|
validates :podcast_id, uniqueness: { scope: :user_id }
|
|
validates :podcast_id, :user_id, presence: true
|
|
end
|