Class: Renalware::Patients::BookmarksQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/patients/bookmarks_query.rb

Defined Under Namespace

Modules: RansackScopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_relation:, params: nil) ⇒ BookmarksQuery

Returns a new instance of BookmarksQuery.



10
11
12
13
14
# File 'app/models/renalware/patients/bookmarks_query.rb', line 10

def initialize(default_relation:, params: nil)
  @default_relation = default_relation
  @query = params || {}
  @query[:s] ||= "created_at desc"
end

Instance Attribute Details

#default_relationObject (readonly)

Returns the value of attribute default_relation.



8
9
10
# File 'app/models/renalware/patients/bookmarks_query.rb', line 8

def default_relation
  @default_relation
end

#queryObject (readonly)

Returns the value of attribute query.



8
9
10
# File 'app/models/renalware/patients/bookmarks_query.rb', line 8

def query
  @query
end

Instance Method Details

#callObject



16
17
18
# File 'app/models/renalware/patients/bookmarks_query.rb', line 16

def call
  search.result
end

#searchObject

Note we MUST join onto patients for PatientsRansackHelper.identity_match to work. It might be better to refactor PatientsRansackHelper so we can include where required eg below using .extending(PatientsRansackHelper) rather than relying on it being in included in the model file. note that adding .includes(:created_by) here creates an ambigous column ‘family_name’ error



26
27
28
29
30
31
32
33
34
35
# File 'app/models/renalware/patients/bookmarks_query.rb', line 26

def search
  @search ||= begin
    (default_relation || Bookmark)
      .extend(RansackScopes)
      .joins(:patient)
      .eager_load(patient: [current_modality: :description])
      .order(created_at: :desc)
      .ransack(query)
  end
end