2020-04-22 19:07:51 +05:30
|
|
|
# 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-06-23 00:09:42 +05:30
|
|
|
super(attrs.reverse_merge(updated_at: Time.current.utc))
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.update_all(attrs = {})
|
2020-06-23 00:09:42 +05:30
|
|
|
super(attrs.reverse_merge(updated_at: Time.current.utc))
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|