2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-08-08 18:48:11 -04:00
|
|
|
class Contract < ActiveRecord::Base
|
|
|
|
belongs_to :company
|
2017-12-31 15:20:00 -05:00
|
|
|
belongs_to :developer, primary_key: :id
|
2016-08-06 13:37:57 -04:00
|
|
|
belongs_to :firm, foreign_key: "company_id"
|
2011-05-31 06:08:11 -04:00
|
|
|
|
2019-02-12 12:06:06 -05:00
|
|
|
attribute :metadata, :json
|
|
|
|
|
|
|
|
before_save :hi, :update_metadata
|
2011-05-31 06:08:11 -04:00
|
|
|
after_save :bye
|
|
|
|
|
|
|
|
attr_accessor :hi_count, :bye_count
|
|
|
|
|
|
|
|
def hi
|
|
|
|
@hi_count ||= 0
|
|
|
|
@hi_count += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def bye
|
|
|
|
@bye_count ||= 0
|
|
|
|
@bye_count += 1
|
|
|
|
end
|
2019-02-12 12:06:06 -05:00
|
|
|
|
|
|
|
def update_metadata
|
2022-02-25 07:30:37 -05:00
|
|
|
# 'code' makes the JSON string consistently orderable, which is used
|
|
|
|
# by RelationsTest "joins with order by custom attribute". Without
|
|
|
|
# this it would still pass 99% of the time, but fail when two
|
|
|
|
# records' company_id lexical and numeric order differ (99, 100).
|
|
|
|
self.metadata = { code: company_id && "%08x" % company_id, company_id: company_id, developer_id: developer_id }
|
2019-02-12 12:06:06 -05:00
|
|
|
end
|
2010-12-12 11:35:27 -05:00
|
|
|
end
|
2018-08-21 11:23:17 -04:00
|
|
|
|
|
|
|
class NewContract < Contract
|
|
|
|
validates :company_id, presence: true
|
|
|
|
end
|
2021-01-04 20:35:36 -05:00
|
|
|
|
|
|
|
class SpecialContract < ActiveRecord::Base
|
|
|
|
self.table_name = "contracts"
|
|
|
|
belongs_to :company
|
|
|
|
belongs_to :special_developer, foreign_key: "developer_id"
|
|
|
|
end
|