Sha256: c32671af32bb3004e0470261430bdb996b193e7d8fd1a79bd6eace321303b2dc

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Jobshop
  class Organization < ApplicationRecord
    self.primary_key = :organization_id

    has_many :users, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :roles, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :places, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :collections, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :things, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :orders, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :companies, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :products, inverse_of: :organization,
      dependent: :restrict_with_exception
    has_many :routing_processes, inverse_of: :organization,
      dependent: :restrict_with_exception

    scope :grouped_by_email, ->(email_addresses) {
      Jobshop::User
        .where(email: email_addresses)
        .joins(:organization)
        .includes(:organization)
        .each_with_object({}) { |user, organizations|
          (organizations[user.email] ||= []) << user.organization
        }
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.157 app/models/jobshop/organization.rb