Last active
October 4, 2019 15:55
-
-
Save c80609a/2bb2c124c0f851c39bffbc95c93109d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Account < ActiveRecord::Base | |
self.table_name = 'accounts' | |
belongs_to :user, class_name: 'User', foreign_key: 'user_id' | |
belongs_to :type, class_name: '::Dictionaries::AccountType' | |
has_one :client, class_name: '::Accounts::Client' | |
has_one :central_agent, class_name: '::Accounts::CentralAgent' | |
has_one :admin, class_name: '::Accounts::Admin' | |
has_one :moderator, class_name: '::Accounts::Moderator' | |
has_one :manager, class_name: '::Accounts::Manager' | |
has_one :manager_guest, class_name: '::Accounts::ManagerGuest' | |
scope :clients, -> { where(type_id: ::Dictionaries::AccountType::CLIENT).where(active: 1) } | |
scope :central_agents, -> { where(type_id: ::Dictionaries::AccountType::CENTRAL_AGENT).where(active: 1) } | |
scope :admins, -> { where(type_id: ::Dictionaries::AccountType::ADMIN).where(active: 1) } | |
scope :moderators, -> { where(type_id: ::Dictionaries::AccountType::MODERATOR).where(active: 1) } | |
scope :managers, -> { where(type_id: ::Dictionaries::AccountType::MANAGER).where(active: 1) } | |
scope :managers_guests, -> { where(type_id: ::Dictionaries::AccountType::MANAGER_GUEST).where(active: 1) } | |
def client? | |
type_id == ::Dictionaries::AccountType::CLIENT | |
end | |
def central_agent? | |
type_id == ::Dictionaries::AccountType::CENTRAL_AGENT | |
end | |
def admin? | |
type_id == ::Dictionaries::AccountType::ADMIN | |
end | |
def moderator? | |
type_id == ::Dictionaries::AccountType::MODERATOR | |
end | |
def manager? | |
type_id == ::Dictionaries::AccountType::MANAGER | |
end | |
def manager_guest? | |
type_id == ::Dictionaries::AccountType::MANAGER_GUEST | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Accounts | |
class CentralAgent < ActiveRecord::Base | |
self.table_name = 'accounts_central_agents' | |
self.primary_key = 'account_id' | |
belongs_to :account, class_name: '::Account', foreign_key: 'account_id' # Родительская запись | |
has_many :bids, class_name: '::Lease::Bid', foreign_key: 'account_id' # Предложения на аренду лодки, сделанные с этого аккаунта | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment