docbrown/app/models/collection.rb
rhymes 71d53873d1
Use Rails 6 new features in the code (#8342)
* Use pick instead of pluck first

* Use touch_all instead of update_all

* Use destroy_by instead of where.destroy_all

* Use scopes

* Fix db:seed:replant

* Remove ActiveSupport::Cache::RedisCacheStore expires_in cache
2020-06-08 16:06:29 -04:00

20 lines
421 B
Ruby

class Collection < ApplicationRecord
has_many :articles
belongs_to :user
belongs_to :organization, optional: true
validates :user_id, presence: true
validates :slug, presence: true, uniqueness: { scope: :user_id }
after_touch :touch_articles
def self.find_series(slug, user)
Collection.find_or_create_by(slug: slug, user: user)
end
private
def touch_articles
articles.touch_all
end
end