2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
require "active_support/core_ext/object/with_options"
|
2009-05-13 04:10:37 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
module MyApplication
|
|
|
|
module Business
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Firm < Company
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :clients, -> { order("id") }, dependent: :destroy
|
|
|
|
has_many :clients_sorted_desc, -> { order("id DESC") }, class_name: "Client"
|
|
|
|
has_many :clients_of_firm, -> { order "id" }, foreign_key: "client_of", class_name: "Client"
|
|
|
|
has_many :clients_like_ms, -> { where("name = 'Microsoft'").order("id") }, class_name: "Client"
|
|
|
|
has_one :account, class_name: "MyApplication::Billing::Account", dependent: :destroy
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Client < Company
|
2016-08-06 13:37:57 -04:00
|
|
|
belongs_to :firm, foreign_key: "client_of"
|
|
|
|
belongs_to :firm_with_other_name, class_name: "Firm", foreign_key: "client_of"
|
2008-04-07 15:44:37 -04:00
|
|
|
|
|
|
|
class Contact < ActiveRecord::Base; end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Developer < ActiveRecord::Base
|
|
|
|
has_and_belongs_to_many :projects
|
2016-08-06 13:37:57 -04:00
|
|
|
validates_length_of :name, within: (3..20)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Project < ActiveRecord::Base
|
|
|
|
has_and_belongs_to_many :developers
|
|
|
|
end
|
|
|
|
|
2010-02-22 05:46:45 -05:00
|
|
|
module Prefixed
|
|
|
|
def self.table_name_prefix
|
2016-08-06 12:26:20 -04:00
|
|
|
"prefixed_"
|
2010-02-22 05:46:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
2014-05-02 21:00:53 -04:00
|
|
|
class Firm < Company
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "companies"
|
2014-05-02 21:00:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Nested
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Suffixed
|
|
|
|
def self.table_name_suffix
|
2016-08-06 12:26:20 -04:00
|
|
|
"_suffixed"
|
2014-05-02 21:00:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
2010-02-22 05:46:45 -05:00
|
|
|
class Firm < Company
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "companies"
|
2010-02-22 05:46:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module Nested
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-02-22 13:44:14 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
module Billing
|
2006-02-22 13:44:14 -05:00
|
|
|
class Firm < ActiveRecord::Base
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "companies"
|
2006-02-22 13:44:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module Nested
|
|
|
|
class Firm < ActiveRecord::Base
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "companies"
|
2006-02-22 13:44:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Account < ActiveRecord::Base
|
2016-08-06 13:37:57 -04:00
|
|
|
with_options(foreign_key: :firm_id) do |i|
|
|
|
|
i.belongs_to :firm, class_name: "MyApplication::Business::Firm"
|
|
|
|
i.belongs_to :qualified_billing_firm, class_name: "MyApplication::Billing::Firm"
|
|
|
|
i.belongs_to :unqualified_billing_firm, class_name: "Firm"
|
|
|
|
i.belongs_to :nested_qualified_billing_firm, class_name: "MyApplication::Billing::Nested::Firm"
|
|
|
|
i.belongs_to :nested_unqualified_billing_firm, class_name: "Nested::Firm"
|
2006-09-15 03:02:05 -04:00
|
|
|
end
|
2013-01-24 07:44:02 -05:00
|
|
|
|
|
|
|
validate :check_empty_credit_limit
|
|
|
|
|
2016-12-23 01:51:03 -05:00
|
|
|
private
|
2016-08-06 13:55:02 -04:00
|
|
|
def check_empty_credit_limit
|
|
|
|
errors.add("credit_card", :blank) if credit_card.blank?
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|