Sha256: 7341851881185ee4e59553bae59c7dd5b5e8fcaa7458432fe176fdc9ed76e083

Contents?: true

Size: 661 Bytes

Versions: 4

Compression:

Stored size: 661 Bytes

Contents

# frozen_string_literal: true

require 'acts_as_list'

module Lcms
  module Engine
    class DownloadCategory < ActiveRecord::Base
      has_many :resource_downloads

      default_scope { order(:position) }

      acts_as_list

      validates :title, uniqueness: true, presence: true

      before_save :unique_bundle

      def self.bundle
        where(bundle: true).first
      end

      private

      def unique_bundle
        # we need the try here, otherwise this will fail when migrating the first time.
        self.class.where.not(id: id).where(bundle: true).update_all(bundle: false) if try(:bundle) && bundle_changed?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lcms-engine-0.1.4 app/models/lcms/engine/download_category.rb
lcms-engine-0.1.3 app/models/lcms/engine/download_category.rb
lcms-engine-0.1.2 app/models/lcms/engine/download_category.rb
lcms-engine-0.1.0 app/models/lcms/engine/download_category.rb