Sha256: cddfdc1bc18bfe0a772a718f1171fe6eb81205264c52391bfea5da86d3f1529a

Contents?: true

Size: 525 Bytes

Versions: 2

Compression:

Stored size: 525 Bytes

Contents

# frozen_string_literal: true

module Thredded
  class MessageboardGroup < ActiveRecord::Base
    has_many :messageboards,
             inverse_of: :group,
             foreign_key: :messageboard_group_id,
             dependent: :nullify

    scope :ordered, -> { order(position: :asc, id: :asc) }
    validates :name, presence: true, uniqueness: true
    validates :position, presence: true, on: :update
    before_save :ensure_position

    def ensure_position
      self.position ||= Time.zone.now.to_i
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thredded-0.16.11 app/models/thredded/messageboard_group.rb
thredded-0.16.10 app/models/thredded/messageboard_group.rb