Sha256: a4de11a2e2899672a686ef88fdf1005253632568309bd4bbdeed609c04634c46

Contents?: true

Size: 686 Bytes

Versions: 1

Compression:

Stored size: 686 Bytes

Contents

module Jobshop
  class Company < ApplicationRecord
    self.primary_keys = [ :organization_id, :company_id ]

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

    belongs_to :organization, inverse_of: :companies
    belongs_to :created_by, class_name: "Jobshop::User",
      foreign_key: [ :organization_id, :created_by_id ]
    has_many :orders, inverse_of: :company,
      foreign_key: [ :organization_id, :company_id ]

    validates :name, presence: true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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