Class: Predicate

Inherits:
ControlledVocabularyTerm show all
Defined in:
app/models/predicate.rb

Constant Summary

Constant Summary

Constants inherited from ControlledVocabularyTerm

ControlledVocabularyTerm::ALTERNATE_VALUES_FOR

Instance Attribute Summary

Attributes inherited from ControlledVocabularyTerm

#definition, #name, #project_id, #type, #uri, #uri_relation

Class Method Summary (collapse)

Methods inherited from ControlledVocabularyTerm

#uri_relation_is_a_skos_relation

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) select_optimized(user_id, project_id, klass)



26
27
28
29
30
31
32
33
34
# File 'app/models/predicate.rb', line 26

def self.select_optimized(user_id, project_id, klass)
  h = {
    recent: Predicate.where(project_id: project_id).used_on_klass(klass).used_recently.limit(10).distinct.to_a,
    pinboard:  Predicate.pinned_by(user_id).where(project_id: project_id).to_a
  }

  h[:quick] = (Predicate.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a  + h[:recent][0..3]).uniq
  h
end

+ (Scope) used_recently

Returns the max 10 most recently used predicates

Returns:

  • (Scope)

    the max 10 most recently used predicates



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/predicate.rb', line 9

def self.used_recently
  i = InternalAttribute.arel_table
  p = Predicate.arel_table

  # i is a select manager
  i = i.project(i['controlled_vocabulary_term_id'], i['created_at']).from(i)
    .where(i['created_at'].gt( 1.weeks.ago ))
    .order(i['created_at'])
   
  # z is a table alias 
  z = i.as('recent_t')

  Predicate.joins(
    Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['controlled_vocabulary_term_id'].eq(p['id'])))
  ).distinct.limit(10)
end