rails_select_on_includes 0.5.7 → 5.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/lib/rails_select_on_includes.rb +67 -60
- data/lib/rails_select_on_includes/version.rb +1 -1
- data/rails_select_on_includes.gemspec +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a469600a55953ed0756cd3c743cb63fe74ee37f3
|
4
|
+
data.tar.gz: bb03a46fd331813f085396cf5da81c9a0233e9e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e1d39a0dcab674aa7e148406f546f5c5b20b403b8be25f9f53e13d651a29a82594b8c329f15f0de18cbeeafb4110d9af3a4c0f9081e59f8b699b593c0402d5
|
7
|
+
data.tar.gz: a812ebc0e9c299de69979ddff256ca89c7e189db8d77c2bcdc8672c65d341dcbc25ad6240923e4d7f507933c7dc4742b4de9cd35275dfa065d57b10c2b035ec8
|
data/README.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
Selected virtual attributes will be now typecasted as usual attributes
|
3
3
|
|
4
4
|
#Rails version
|
5
|
-
Supports rails 4.x and rails 5 now!
|
6
|
-
|
5
|
+
Supports rails 4.x and rails 5-5.1.4, and 5.1.5 now!
|
6
|
+
|
7
|
+
Master is now runs on rails 5.1.5,
|
8
|
+
rails_5.1.4 branch is for rails less than 5.1.5,
|
9
|
+
rails_4 branch is for rails 4 support
|
7
10
|
|
8
11
|
# RailsSelectOnIncludes
|
9
12
|
|
@@ -69,10 +72,13 @@ Add this line to your application's Gemfile:
|
|
69
72
|
|
70
73
|
```ruby
|
71
74
|
#rails 4
|
72
|
-
gem 'rails_select_on_includes', '~> 0.4.
|
75
|
+
gem 'rails_select_on_includes', '~> 0.4.11'
|
76
|
+
|
77
|
+
#rails 5.1.4
|
78
|
+
gem 'rails_select_on_includes', '~> 5.1.4.0'
|
73
79
|
|
74
|
-
#rails 5
|
75
|
-
gem 'rails_select_on_includes', '~>
|
80
|
+
#rails 5.1.5
|
81
|
+
gem 'rails_select_on_includes', '~> 5.1.5.0'
|
76
82
|
```
|
77
83
|
|
78
84
|
And then execute:
|
@@ -62,80 +62,87 @@ require 'active_support/core_ext/string/filters'
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
#
|
65
66
|
::ActiveRecord::Associations::JoinDependency::JoinBase.class_eval do
|
66
67
|
def instantiate(row, aliases, column_types = {}, &block)
|
67
68
|
base_klass.instantiate(extract_record(row, aliases), column_types, &block)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
72
|
+
|
71
73
|
::ActiveRecord::Associations::JoinDependency.class_eval do
|
72
|
-
def instantiate(result_set,
|
73
|
-
|
74
|
+
def instantiate(result_set, &block)
|
75
|
+
primary_key = aliases.column_alias(join_root, join_root.primary_key)
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
seen = Hash.new { |i, object_id|
|
78
|
+
i[object_id] = Hash.new { |j, child_class|
|
79
|
+
j[child_class] = {}
|
80
|
+
}
|
78
81
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
class_name: join_root.base_klass.name
|
90
|
-
}
|
91
|
-
|
92
|
-
message_bus.instrument('instantiation.active_record', payload) do
|
93
|
-
result_set.each { |row_hash|
|
94
|
-
parent_key = primary_key ? row_hash[primary_key] : row_hash
|
95
|
-
# DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
|
96
|
-
# PREVIOUS > join_root.instantiate(row_hash, column_aliases )
|
97
|
-
parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
|
98
|
-
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
|
82
|
+
|
83
|
+
model_cache = Hash.new { |h, klass| h[klass] = {} }
|
84
|
+
parents = model_cache[join_root]
|
85
|
+
column_aliases = aliases.column_aliases join_root
|
86
|
+
|
87
|
+
message_bus = ActiveSupport::Notifications.instrumenter
|
88
|
+
|
89
|
+
payload = {
|
90
|
+
record_count: result_set.length,
|
91
|
+
class_name: join_root.base_klass.name
|
99
92
|
}
|
100
|
-
end
|
101
|
-
parents.values
|
102
|
-
end
|
103
|
-
end
|
104
93
|
|
94
|
+
message_bus.instrument("instantiation.active_record", payload) do
|
95
|
+
result_set.each { |row_hash|
|
96
|
+
parent_key = primary_key ? row_hash[primary_key] : row_hash
|
97
|
+
# DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
|
98
|
+
# PREVIOUS > join_root.instantiate(row_hash, column_aliases )
|
99
|
+
# parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, &block)
|
105
100
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
# failing to do so means that in cases like activerecord/test/cases/associations/inner_join_association_test.rb:136
|
112
|
-
# incorrect SQL is generated. In that case, the join dependency for
|
113
|
-
# SpecialCategorizations is constructed without knowledge of the
|
114
|
-
# preexisting join in joins_values to categorizations (by way of
|
115
|
-
# the `has_many :through` for categories).
|
116
|
-
#
|
117
|
-
join_dependency = construct_join_dependency(joins_values)
|
118
|
-
|
119
|
-
aliases = join_dependency.aliases
|
120
|
-
relation = select aliases.columns
|
121
|
-
relation = apply_join_dependency(relation, join_dependency)
|
122
|
-
|
123
|
-
if block_given?
|
124
|
-
yield relation
|
125
|
-
else
|
126
|
-
if ActiveRecord::NullRelation === relation
|
127
|
-
[]
|
128
|
-
else
|
129
|
-
arel = relation.arel
|
130
|
-
rows = connection.select_all(arel, 'SQL', relation.bound_attributes)
|
131
|
-
#1 DISTINCTION IS HERE:
|
132
|
-
# now we gently mokey-patching existing column aliases with select values
|
133
|
-
aliases.update_aliases_to_select_values(values[:select]) unless values[:select].blank?
|
134
|
-
|
135
|
-
join_dependency.instantiate(rows, aliases)
|
136
|
-
end
|
101
|
+
parent = parents[parent_key] ||=
|
102
|
+
join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ), &block )
|
103
|
+
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
|
104
|
+
}
|
137
105
|
end
|
106
|
+
|
107
|
+
parents.values
|
138
108
|
end
|
139
109
|
end
|
140
110
|
|
141
111
|
|
112
|
+
::ActiveRecord::Relation.class_eval do
|
113
|
+
private
|
114
|
+
|
115
|
+
def exec_queries(&block)
|
116
|
+
@records =
|
117
|
+
if eager_loading?
|
118
|
+
find_with_associations do |relation, join_dependency|
|
119
|
+
if ActiveRecord::NullRelation === relation
|
120
|
+
[]
|
121
|
+
else
|
122
|
+
rows = connection.select_all(relation.arel, "SQL", relation.bound_attributes)
|
123
|
+
#1 DISTINCTION IS HERE:
|
124
|
+
# now we gently mokey-patching existing column aliases with select values
|
125
|
+
join_dependency.aliases.update_aliases_to_select_values(values[:select]) unless values[:select].blank?
|
126
|
+
|
127
|
+
join_dependency.instantiate(rows, &block)
|
128
|
+
end.freeze
|
129
|
+
end
|
130
|
+
else
|
131
|
+
klass.find_by_sql(arel, bound_attributes, &block).freeze
|
132
|
+
end
|
133
|
+
|
134
|
+
preload = preload_values
|
135
|
+
preload += includes_values unless eager_loading?
|
136
|
+
preloader = nil
|
137
|
+
preload.each do |associations|
|
138
|
+
preloader ||= build_preloader
|
139
|
+
preloader.preload @records, associations
|
140
|
+
end
|
141
|
+
|
142
|
+
@records.each(&:readonly!) if readonly_value
|
143
|
+
|
144
|
+
@loaded = true
|
145
|
+
@records
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency "activerecord",
|
33
|
+
spec.add_dependency "activerecord", '>= 5', '<= 5.1.4'
|
34
34
|
|
35
35
|
spec.add_development_dependency "rails", ">=5"
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.13"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_select_on_includes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5'
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5'
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rails
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|