Welcome to mirror list, hosted at ThFree Co, Russian Federation.

slug.rb « wiki_page « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c1725d3492178fb4a9922baa9c03a49f941b3779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 = {})
      super(attrs.reverse_merge(updated_at: Time.current.utc))
    end

    def self.update_all(attrs = {})
      super(attrs.reverse_merge(updated_at: Time.current.utc))
    end
  end
end