Class: BusinessUnit
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BusinessUnit
- Includes:
- Models::Auditable
- Defined in:
- app/models/business_unit.rb
Overview
== Schema Information
Table name: business_units
Database name: primary
id :integer not null, primary key
name :string(255)
number :integer
created_at :datetime
updated_at :datetime
company_id :integer
Indexes
business_units_company_id_idx (company_id)
idx_business_unit_number (number)
Foreign Keys
business_units_company_id_fkey (company_id => companies.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #company_id ⇒ Object readonly
- #name ⇒ Object readonly
- #number ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
- #budgets ⇒ ActiveRecord::Relation<Budget>
- #invoices ⇒ ActiveRecord::Relation<Invoice>
- #suppliers ⇒ ActiveRecord::Relation<Supplier>
Class Method Summary collapse
-
.by_number ⇒ ActiveRecord::Relation<BusinessUnit>
A relation of BusinessUnits that are by number.
-
.for_company ⇒ ActiveRecord::Relation<BusinessUnit>
A relation of BusinessUnits that are for company.
- .select_options ⇒ Object
Instance Method Summary collapse
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#company_id ⇒ Object (readonly)
30 |
# File 'app/models/business_unit.rb', line 30 validates :number, :name, :company_id, presence: true |
#name ⇒ Object (readonly)
30 |
# File 'app/models/business_unit.rb', line 30 validates :number, :name, :company_id, presence: true |
#number ⇒ Object (readonly)
30 |
# File 'app/models/business_unit.rb', line 30 validates :number, :name, :company_id, presence: true |
Class Method Details
.by_number ⇒ ActiveRecord::Relation<BusinessUnit>
A relation of BusinessUnits that are by number. Active Record Scope
33 |
# File 'app/models/business_unit.rb', line 33 scope :by_number, -> { order(:number) } |
.for_company ⇒ ActiveRecord::Relation<BusinessUnit>
A relation of BusinessUnits that are for company. Active Record Scope
34 |
# File 'app/models/business_unit.rb', line 34 scope :for_company, ->(company_id) { where(company_id: company_id) } |
.select_options ⇒ Object
40 41 42 |
# File 'app/models/business_unit.rb', line 40 def self. all.order('number asc').map { |bu| [bu.number_and_name, bu.id] } end |
Instance Method Details
#budgets ⇒ ActiveRecord::Relation<Budget>
27 |
# File 'app/models/business_unit.rb', line 27 has_many :budgets |
#company ⇒ Company
25 |
# File 'app/models/business_unit.rb', line 25 belongs_to :company, optional: true |
#invoices ⇒ ActiveRecord::Relation<Invoice>
28 |
# File 'app/models/business_unit.rb', line 28 has_many :invoices |
#number_and_name ⇒ Object
36 37 38 |
# File 'app/models/business_unit.rb', line 36 def number_and_name "#{number} #{name}" end |
#suppliers ⇒ ActiveRecord::Relation<Supplier>
26 |
# File 'app/models/business_unit.rb', line 26 has_many :suppliers |