rails_select_on_includes 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 443283f4904c4f4329a5a32983f4defe8a63a5e3
4
- data.tar.gz: 53601f7583dc63c766b8182c0d6b485bd6295cfe
3
+ metadata.gz: 63afc846674a71d9b60199a542ac6842ad09c134
4
+ data.tar.gz: f7c43c0cbfdae603b95c066f6e6575ad161b1e90
5
5
  SHA512:
6
- metadata.gz: be9bd630a495fd6874d118f2cc06959e18ae792775ede4f0ff44a44d0f5a783606e8a2f47ced47279f01e1f66b7ec5410d58b585da2bec1fbc6532e033e97387
7
- data.tar.gz: 7f64aa60dfbfc950696ff200441941482bab8494ecc4d8b167cf2a0207db4f1a5fb9b708760db83bc87d1e6786c2db515e8093d2a9c98a72ab037f6f77f5127d
6
+ metadata.gz: 3e469be7fdc9d1b389a3a20647baf475dfe8f625f84ee560b4d9c348af5b87db06064402e3453fce553fbe8bc3675def092a4c93bf6211872aaf73d61611f8f4
7
+ data.tar.gz: c7cf417cc7771e2d9248e02092678e214d4012a6a003a67680e3ba29125898dd697c18f31ee5bee8d5288e6a6e6e829c9dbc4d434a3ab6033f505ad86d95b60e
@@ -18,6 +18,8 @@ module ActiveRecord
18
18
  }
19
19
  @base_class_node_aliases ||= h[table.node] if table.node.is_a?(ActiveRecord::Associations::JoinDependency::JoinBase)
20
20
  }
21
+
22
+ @virtual_attributes_names = []
21
23
  end
22
24
  # valid formats are:
23
25
  # 1 'table_name.column' or 'table_name.column as column_1' will be parsed! distinct on can be used also
@@ -29,22 +31,28 @@ module ActiveRecord
29
31
  # if sv is symbol that we assume that its a base table column and it will be aliased and added as usual
30
32
  # all we need is some specials joins+select from related tables
31
33
  if sv.is_a?(Hash)
32
- flatten_hash_values(sv).each{|sub_sv| @base_class_node_aliases << [sub_sv, sub_sv] }
34
+ flatten_hash_values(sv).each{|sub_sv| @base_class_node_aliases << [sub_sv, sub_sv]; @virtual_attributes_names << sub_sv }
33
35
  elsif sv.is_a?(String)
34
36
  # this is the case of long raw select
35
37
  sv.split( ", " ).each do |sub_sv|
36
38
  if sub_sv[/.+ as .+/i]
37
39
  selected_column = sub_sv[/ as .+/i][4..-1]
38
40
  @base_class_node_aliases << [selected_column, selected_column]
41
+ @virtual_attributes_names << selected_column
39
42
  elsif sub_sv[/.+\.[^\*]+/]
40
43
  selected_column = sub_sv[/\..+/][1..-1]
41
44
  @base_class_node_aliases << [selected_column, selected_column]
45
+ @virtual_attributes_names << selected_column
42
46
  end
43
47
  end
44
48
  end
45
49
  end
46
50
  end
47
51
 
52
+ def slice_selected_attr_types( column_types )
53
+ column_types.slice( *@virtual_attributes_names )
54
+ end
55
+
48
56
  private
49
57
  def flatten_hash_values( some_hash )
50
58
  some_hash.values.map{ |value| value.is_a?(Hash) ? flatten_hash_values( value ) : value }.flatten
@@ -80,9 +88,9 @@ module ActiveRecord
80
88
  message_bus.instrument('instantiation.active_record', payload) do
81
89
  result_set.each { |row_hash|
82
90
  parent_key = primary_key ? row_hash[primary_key] : row_hash
83
- # DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, result_set.column_types )
84
- # PREVIOUS join_root.instantiate(row_hash, column_aliases )
85
- parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, result_set.column_types )
91
+ # DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
92
+ # PREVIOUS > join_root.instantiate(row_hash, column_aliases )
93
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
86
94
  construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
87
95
  }
88
96
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSelectOnIncludes
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_select_on_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl