-
Notifications
You must be signed in to change notification settings - Fork 1
/
organization.rb
36 lines (30 loc) · 1014 Bytes
/
organization.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true
# typed: true
# == Schema Information
#
# Table name: organizations
#
# id :integer not null, primary key
# sway_locale_id :integer not null
# name :string not null
# icon_path :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Organization < ApplicationRecord
extend T::Sig
belongs_to :sway_locale
has_many :organization_bill_positions, inverse_of: :organization, dependent: :destroy
has_many :bills, through: :organization_bill_positions
validates :name, uniqueness: {scope: :sway_locale_id, allow_nil: true}
sig { params(with_positions: T::Boolean).returns(Jbuilder) }
def to_builder(with_positions:)
Jbuilder.new do |o|
o.id id
o.sway_locale_id sway_locale_id
o.name name
o.icon_path icon_path
o.positions(organization_bill_positions.map { |obp| obp.to_builder.attributes! }) if with_positions
end
end
end