Class: Project

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba

scope by dba organization

Parameters:

  • dba_organization (Party)

    dba organization to scope by

Returns:

  • (ActiveRecord::Relation)


22
23
24
# File 'app/models/project.rb', line 22

def scope_by_dba_organization(dba_organization)
  scope_by_party(dba_organization, {role_types: [RoleType.iid('dba_org')]})
end

.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation

scope by party

or an array of Party ids

Parameters:

  • party (Integer | Party | Array)

    either a id of Party record, a Party record, an array of Party records

  • options (Hash) (defaults to: {})

    options to apply to this scope

Options Hash (options):

  • :role_types (Array)

    role types to include in the scope

Returns:

  • (ActiveRecord::Relation)


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/project.rb', line 36

def scope_by_party(party, options={})
  table_alias = String.random

  statement = joins("inner join entity_party_roles as \"#{table_alias}\" on \"#{table_alias}\".entity_record_id = projects.id
                     and \"#{table_alias}\".entity_record_type = 'Project'")
                  .where("#{table_alias}.party_id" => party).uniq

  if options[:role_types]
    statement = statement.where("#{table_alias}.role_type_id" => RoleType.find_child_role_types(options[:role_types]))
  end

  statement
end

Instance Method Details

#to_data_hashObject



55
56
57
# File 'app/models/project.rb', line 55

def to_data_hash
  to_hash(only: [:id, :description, :created_at, :updated_at])
end

#to_labelObject



51
52
53
# File 'app/models/project.rb', line 51

def to_label
  description
end