Sha256: 8d9693076de53a0542cecbc5d0a1e9d0124ae5e1416746bd2b7381919d94e44b

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

module Jobshop
  class Collection < ApplicationRecord
    self.primary_keys = [ :organization_id, :collection_id ]

    after_create do
      self.class.connection.clear_query_cache
      fresh_collection = self.class.unscoped {
        self.class.find_by!(organization: organization, name: name)
      }
      @attributes = fresh_collection.instance_variable_get(:@attributes)
      @new_record = false
      self
    end

    belongs_to :organization, inverse_of: :collections
    has_many :things, inverse_of: :collection,
      foreign_key: [ :organization_id, :collection_id ]

    validates :name, presence: true,
      uniqueness: { scope: :organization_id, case_sensitive: false }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.157 app/models/jobshop/collection.rb