forest_liana 2.15.0 → 2.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59e796ce07d5f7cf5d236297e5a1d26c1b4e61a7
4
- data.tar.gz: 6400747da9d29cf2c57f974adfffb13de3b67212
3
+ metadata.gz: 7bd3f2c3c9cf89f5d5e79c20f9d4a9200606d406
4
+ data.tar.gz: 3c59725cc8ea52cec5c8c740abbe91ba27c652c7
5
5
  SHA512:
6
- metadata.gz: d26d075f6a1b202c3e5ef0195f61e223facc232e0d8e1eee908659591a7e53dde268973f14ab20b7abf77992a1a8115f2ee795008663057473067fae9680bc58
7
- data.tar.gz: 2407895f42b1715cf3268978220bbde83df807ac4c3fb0133aa6a897454b5e50dd5eee814057fb0e5b3c06598ddbe8afca734b5ec398fcf1fed3d6185732d660
6
+ metadata.gz: aa970760952ecd97515c1b63a138b9de2a9dc472233a2267dbc1bfecd03f8764f7310bb0f9316f164493b34cae520e7230f676d42f361ad081c83d96c454cf80
7
+ data.tar.gz: 5cb1f52d3b1a8a751f7312e4fe93ac6737767e9ea8d1bbd8e1c9df789e4b55d08c7d13ac692bdd49a30ce8a1013ca3531f40e1f0c7c679b4d3d56a8dd0c09f88
@@ -14,7 +14,7 @@ module ForestLiana
14
14
  end
15
15
 
16
16
  def includes_for_serialization
17
- includes_initial = includes
17
+ includes_initial = @includes
18
18
  includes_for_smart_belongs_to = @collection.fields_smart_belongs_to.map { |field| field[:field] }
19
19
 
20
20
  if @field_names_requested
@@ -23,5 +23,13 @@ module ForestLiana
23
23
 
24
24
  includes_initial.concat(includes_for_smart_belongs_to).map(&:to_s)
25
25
  end
26
+
27
+ private
28
+
29
+ def compute_includes
30
+ @includes = SchemaUtils.one_associations(@resource)
31
+ .select { |association| SchemaUtils.model_included?(association.klass) }
32
+ .map(&:name)
33
+ end
26
34
  end
27
35
  end
@@ -10,8 +10,9 @@ module ForestLiana
10
10
  @collection_name = ForestLiana.name_for(model_association)
11
11
  @field_names_requested = field_names_requested
12
12
  @collection = get_collection(@collection_name)
13
- includes_symbols = includes.map { |association| association.to_sym }
14
- @search_query_builder = SearchQueryBuilder.new(@params, includes_symbols, @collection)
13
+ compute_includes()
14
+ includes_symbols = @includes.map { |association| association.to_sym }
15
+ @search_query_builder = SearchQueryBuilder.new(@params, includes_symbols, {}, @collection)
15
16
 
16
17
  prepare_query()
17
18
  end
@@ -29,8 +30,18 @@ module ForestLiana
29
30
  @search_query_builder.perform(@records)
30
31
  end
31
32
 
32
- def includes
33
- @association.klass
33
+ def query_for_batch
34
+ @records
35
+ end
36
+
37
+ def records
38
+ @records.limit(limit).offset(offset)
39
+ end
40
+
41
+ private
42
+
43
+ def compute_includes
44
+ @includes = @association.klass
34
45
  .reflect_on_all_associations
35
46
  .select do |association|
36
47
  inclusion = !association.options[:polymorphic] &&
@@ -46,16 +57,6 @@ module ForestLiana
46
57
  .map { |association| association.name.to_s }
47
58
  end
48
59
 
49
- def query_for_batch
50
- @records
51
- end
52
-
53
- def records
54
- @records.limit(limit).offset(offset)
55
- end
56
-
57
- private
58
-
59
60
  def field_names_requested
60
61
  return nil unless @params[:fields] && @params[:fields][@collection_name]
61
62
  @params[:fields][@collection_name].split(',')
@@ -74,7 +75,7 @@ module ForestLiana
74
75
  @records = get_resource()
75
76
  .find(@params[:id])
76
77
  .send(@params[:association_name])
77
- .eager_load(includes)
78
+ .eager_load(@includes)
78
79
  end
79
80
 
80
81
  def offset
@@ -1,9 +1,10 @@
1
1
  module ForestLiana
2
2
  class LeaderboardStatGetter < StatGetter
3
3
  def initialize(resource, params)
4
- super(resource, params)
5
-
4
+ @resource = resource
5
+ @params = params
6
6
  @model_relationship = @resource.reflect_on_association(@params[:relationship_field]).klass
7
+ compute_includes()
7
8
  @label_field = @params[:label_field]
8
9
  @aggregate = @params[:aggregate].downcase
9
10
  @aggregate_field = @params[:aggregate_field]
@@ -13,7 +14,7 @@ module ForestLiana
13
14
 
14
15
  def perform
15
16
  result = @model_relationship
16
- .joins(includes)
17
+ .joins(@includes)
17
18
  .group(@groub_by)
18
19
  .order(order)
19
20
  .limit(@limit)
@@ -23,8 +24,8 @@ module ForestLiana
23
24
  @record = Model::Stat.new(value: result)
24
25
  end
25
26
 
26
- def includes
27
- SchemaUtils.one_associations(@model_relationship)
27
+ def compute_includes
28
+ @includes = SchemaUtils.one_associations(@model_relationship)
28
29
  .select { |association| SchemaUtils.model_included?(association.klass) }
29
30
  .map(&:name)
30
31
  end
@@ -20,7 +20,7 @@ module ForestLiana
20
20
  end
21
21
 
22
22
  def perform
23
- value = get_resource().eager_load(includes)
23
+ value = get_resource().eager_load(@includes)
24
24
 
25
25
  if @params[:filterType] && @params[:filters]
26
26
  conditions = []
@@ -19,7 +19,7 @@ module ForestLiana
19
19
  end
20
20
 
21
21
  result = get_resource()
22
- .eager_load(includes)
22
+ .eager_load(@includes)
23
23
  .where(conditions.join(filter_operator))
24
24
  .group(group_by_field)
25
25
  .order(order)
@@ -62,7 +62,7 @@ module ForestLiana
62
62
  if @params[:aggregate].downcase == 'sum'
63
63
  field = @params[:aggregate_field].downcase
64
64
  else
65
- field = Rails::VERSION::MAJOR >= 5 || includes.size > 0 ? 'id' : 'all'
65
+ field = Rails::VERSION::MAJOR >= 5 || @includes.size > 0 ? 'id' : 'all'
66
66
  end
67
67
  "#{@params[:aggregate].downcase}_#{field} #{order}"
68
68
  end
@@ -7,17 +7,11 @@ module ForestLiana
7
7
  @params = params
8
8
  @collection_name = ForestLiana.name_for(@resource)
9
9
  @collection = get_collection(@collection_name)
10
+ compute_includes()
10
11
  end
11
12
 
12
13
  def perform
13
- @record = get_resource().eager_load(includes).find(@params[:id])
14
+ @record = get_resource().eager_load(@includes).find(@params[:id])
14
15
  end
15
-
16
- def includes
17
- SchemaUtils.one_associations(@resource)
18
- .select { |association| SchemaUtils.model_included?(association.klass) }
19
- .map(&:name)
20
- end
21
-
22
16
  end
23
17
  end
@@ -10,21 +10,23 @@ module ForestLiana
10
10
  @collection_name = ForestLiana.name_for(@resource)
11
11
  @collection = get_collection(@collection_name)
12
12
  @field_names_requested = field_names_requested
13
+ @tables_associated_to_relations_name = {}
13
14
  get_segment()
14
- @search_query_builder = SearchQueryBuilder.new(@params, includes, @collection)
15
+ compute_includes()
16
+ @search_query_builder = SearchQueryBuilder.new(@params, @includes, @tables_associated_to_relations_name, @collection)
15
17
 
16
18
  prepare_query()
17
19
  end
18
20
 
19
21
  def perform
20
- @records = @records.eager_load(includes)
22
+ @records = @records.eager_load(@includes)
21
23
  @records_sorted = sort_query
22
24
  end
23
25
 
24
26
  def count
25
- # NOTICE: For performance reasons, do not eager load the data if there is
26
- # no search or filters on associations.
27
- @records_count = @count_needs_includes ? @records.eager_load(includes).count : @records.count
27
+ # NOTICE: For performance reasons, do not eager load the data if there is no search or
28
+ # filters on associations.
29
+ @records_count = @count_needs_includes ? @records.eager_load(@includes).count : @records.count
28
30
  end
29
31
 
30
32
  def query_for_batch
@@ -35,10 +37,18 @@ module ForestLiana
35
37
  @records_sorted.offset(offset).limit(limit).to_a
36
38
  end
37
39
 
38
- def includes
39
- includes = SchemaUtils.one_associations(@resource)
40
+ def compute_includes
41
+ associations_has_one = SchemaUtils.one_associations(@resource)
40
42
  .select { |association| SchemaUtils.model_included?(association.klass) }
41
- .map(&:name)
43
+
44
+ includes = associations_has_one.each do |association|
45
+ if @tables_associated_to_relations_name[association.table_name].nil?
46
+ @tables_associated_to_relations_name[association.table_name] = []
47
+ end
48
+ @tables_associated_to_relations_name[association.table_name] << association.name
49
+ end
50
+
51
+ includes = associations_has_one.map(&:name)
42
52
  includes_for_smart_search = []
43
53
 
44
54
  if @collection && @collection.search_fields
@@ -54,9 +64,9 @@ module ForestLiana
54
64
  end
55
65
 
56
66
  if @field_names_requested
57
- (includes & @field_names_requested).concat(includes_for_smart_search)
67
+ @includes = (includes & @field_names_requested).concat(includes_for_smart_search)
58
68
  else
59
- includes
69
+ @includes = includes
60
70
  end
61
71
  end
62
72
 
@@ -4,12 +4,13 @@ module ForestLiana
4
4
 
5
5
  attr_reader :fields_searched
6
6
 
7
- def initialize(params, includes, collection)
7
+ def initialize(params, includes, tables_associated_to_relations_name, collection)
8
8
  @params = params
9
9
  @includes = includes
10
10
  @collection = collection
11
11
  @fields_searched = []
12
12
  @search = @params[:search]
13
+ @tables_associated_to_relations_name = tables_associated_to_relations_name
13
14
  end
14
15
 
15
16
  def perform(resource)
@@ -273,12 +274,22 @@ module ForestLiana
273
274
  association_name_pluralized = association_name.pluralize
274
275
 
275
276
  if [association_name, association_name_pluralized].include? association.table_name
276
- # NOTICE: Default case. When the belongsTo association name and the referenced table name are identical.
277
+ # NOTICE: Default case. When the belongsTo association name and the referenced table name
278
+ # are identical.
277
279
  association_name_for_condition = association.table_name
278
280
  else
279
- # NOTICE: When the the belongsTo association name and the referenced table name are identical.
280
- # Format with the ActiveRecord query generator style.
281
- association_name_for_condition = "#{association_name_pluralized}_#{@resource.table_name}"
281
+ # NOTICE: When the the belongsTo association name and the referenced table name are not
282
+ # identical. Format with the ActiveRecord query generator style.
283
+ relations_on_this_table = @tables_associated_to_relations_name[association.table_name]
284
+ has_several_associations_to_the_table_and_is_not_first_one =
285
+ !relations_on_this_table.nil? && relations_on_this_table.size > 1 &&
286
+ relations_on_this_table.find_index(association.name) > 0
287
+
288
+ if has_several_associations_to_the_table_and_is_not_first_one
289
+ association_name_for_condition = "#{association_name_pluralized}_#{@resource.table_name}"
290
+ else
291
+ association_name_for_condition = association.table_name
292
+ end
282
293
  end
283
294
 
284
295
  @records.where("#{association_name_for_condition}.#{subfield} #{filter}")
@@ -5,14 +5,7 @@ module ForestLiana
5
5
  def initialize(resource, params)
6
6
  @resource = resource
7
7
  @params = params
8
- end
9
-
10
- private
11
-
12
- def includes
13
- SchemaUtils.one_associations(@resource)
14
- .select { |association| SchemaUtils.model_included?(association.klass) }
15
- .map(&:name)
8
+ compute_includes()
16
9
  end
17
10
  end
18
11
  end
@@ -4,8 +4,8 @@ module ForestLiana
4
4
 
5
5
  def perform
6
6
  return if @params[:aggregate].blank?
7
- valueCurrent = get_resource().eager_load(includes)
8
- valuePrevious = get_resource().eager_load(includes)
7
+ valueCurrent = get_resource().eager_load(@includes)
8
+ valuePrevious = get_resource().eager_load(@includes)
9
9
  filter_date_interval = false
10
10
 
11
11
  if @params[:filterType] && @params[:filters]
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "2.15.0"
2
+ VERSION = "2.15.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-01 00:00:00.000000000 Z
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails