2020-03-19 08:09:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class WikiPage
|
|
|
|
class Slug < ApplicationRecord
|
|
|
|
self.table_name = 'wiki_page_slugs'
|
|
|
|
|
|
|
|
belongs_to :wiki_page_meta, class_name: 'WikiPage::Meta', inverse_of: :slugs
|
|
|
|
|
|
|
|
validates :slug, presence: true, uniqueness: { scope: :wiki_page_meta_id }
|
|
|
|
validates :canonical, uniqueness: {
|
|
|
|
scope: :wiki_page_meta_id,
|
|
|
|
if: :canonical?,
|
|
|
|
message: 'Only one slug can be canonical per wiki metadata record'
|
|
|
|
}
|
|
|
|
|
|
|
|
scope :canonical, -> { where(canonical: true) }
|
|
|
|
|
|
|
|
def update_columns(attrs = {})
|
2020-05-22 05:08:09 -04:00
|
|
|
super(attrs.reverse_merge(updated_at: Time.current.utc))
|
2020-03-19 08:09:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.update_all(attrs = {})
|
2020-05-22 05:08:09 -04:00
|
|
|
super(attrs.reverse_merge(updated_at: Time.current.utc))
|
2020-03-19 08:09:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|