Sha256: 4a9c525a3f231904d9d1ee950a2756545c1e7a12c5819789b3a6436e167ecb01

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

module BridgeCache
  class Program < BridgeBaseModel
    extend BridgeCache::Data::BridgeModel

    belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: BridgeCache::Domain.name, optional: true
    belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: BridgeCache::Domain.name, optional: true
    has_many :program_items, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: BridgeCache::ProgramItem.name
    has_many :program_enrollments, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: BridgeCache::ProgramEnrollment.name
    has_many :program_group_enrollments, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: BridgeCache::ProgramGroupEnrollment.name
    has_many :affiliated_sub_accounts, primary_key: BridgeCache.primary_key, class_name: BridgeCache::AffiliatedSubAccount.name, as: :item
    has_many :domains, through: :affiliated_sub_accounts

    def self.for_domain(domain_id)
      includes(:domains)
        .where('bridge_cache_affiliated_sub_accounts.domain_id = ? OR bridge_cache_programs.sub_account_id = ?', domain_id, domain_id)
        .references(:domains)
    end

    def self.unique_column_names
      %w[bridge_id]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bridge_cache-0.3.19 app/models/bridge_cache/program.rb
bridge_cache-0.3.17 app/models/bridge_cache/program.rb
bridge_cache-0.3.16 app/models/bridge_cache/program.rb
bridge_cache-0.3.15 app/models/bridge_cache/program.rb
bridge_cache-0.3.14 app/models/bridge_cache/program.rb
bridge_cache-0.3.13 app/models/bridge_cache/program.rb
bridge_cache-0.3.12 app/models/bridge_cache/program.rb
bridge_cache-0.3.11 app/models/bridge_cache/program.rb
bridge_cache-0.3.10 app/models/bridge_cache/program.rb
bridge_cache-0.3.9 app/models/bridge_cache/program.rb