sunstone 8.0.0 → 8.1.0
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 +4 -4
- data/CHANGELOG.md +43 -0
- data/README.md +221 -0
- data/ext/active_record/associations/collection_association.rb +45 -63
- data/ext/active_record/associations/has_many_through_association.rb +21 -0
- data/ext/active_record/associations.rb +12 -10
- data/ext/active_record/attribute_methods.rb +4 -2
- data/ext/active_record/base.rb +16 -0
- data/ext/active_record/callbacks.rb +4 -2
- data/ext/active_record/locking/optimistic.rb +60 -0
- data/ext/active_record/persistence.rb +35 -12
- data/ext/active_record/relation/calculations.rb +26 -24
- data/ext/active_record/relation/finder_methods.rb +165 -0
- data/ext/active_record/relation/predicate_builder.rb +91 -0
- data/ext/active_record/relation/query_methods.rb +6 -1
- data/ext/active_record/relation.rb +5 -0
- data/ext/active_record/statement_cache.rb +11 -3
- data/ext/active_record/transactions.rb +29 -15
- data/ext/active_support/core_ext/object/to_query.rb +2 -0
- data/ext/arel/attributes/empty_relation.rb +2 -0
- data/ext/arel/nodes/eager_load.rb +2 -0
- data/ext/arel/nodes/select_statement.rb +2 -0
- data/ext/arel/select_manager.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/column.rb +4 -1
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +12 -1
- data/lib/active_record/connection_adapters/sunstone/quoting.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/schema_dumper.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +6 -4
- data/lib/active_record/connection_adapters/sunstone/type/array.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type/binary.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type/date_time.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type/ewkb.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type/json.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type/uuid.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +2 -0
- data/lib/arel/collectors/sunstone.rb +15 -5
- data/lib/arel/visitors/sunstone.rb +2 -3
- data/lib/sunstone/connection.rb +2 -0
- data/lib/sunstone/exception.rb +2 -0
- data/lib/sunstone/gis.rb +2 -0
- data/lib/sunstone/version.rb +3 -1
- data/lib/sunstone.rb +9 -1
- metadata +23 -16
- data/ext/active_record/finder_methods.rb +0 -246
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveRecord
|
|
2
4
|
module ConnectionAdapters
|
|
3
5
|
module Sunstone
|
|
@@ -59,16 +61,16 @@ module ActiveRecord
|
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def new_column(name, options)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
cast_type = lookup_cast_type(options)
|
|
65
|
+
sql_type_metadata = fetch_type_metadata(cast_type, options)
|
|
66
|
+
SunstoneColumn.new(name, cast_type, sql_type_metadata, options)
|
|
64
67
|
end
|
|
65
68
|
|
|
66
69
|
def lookup_cast_type(options)
|
|
67
70
|
@type_map.lookup(options['type'], options.symbolize_keys)
|
|
68
71
|
end
|
|
69
72
|
|
|
70
|
-
def fetch_type_metadata(options)
|
|
71
|
-
cast_type = lookup_cast_type(options)
|
|
73
|
+
def fetch_type_metadata(cast_type, options)
|
|
72
74
|
simple_type = SqlTypeMetadata.new(
|
|
73
75
|
sql_type: options['type'],
|
|
74
76
|
type: cast_type.type,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Arel
|
|
2
4
|
module Collectors
|
|
3
5
|
class Sunstone < Arel::Collectors::Bind
|
|
@@ -136,16 +138,24 @@ module Arel
|
|
|
136
138
|
|
|
137
139
|
case operation
|
|
138
140
|
when :count
|
|
139
|
-
path
|
|
141
|
+
path << "/#{operation}"
|
|
140
142
|
when :calculate
|
|
141
|
-
path
|
|
143
|
+
path << "/calculate"
|
|
142
144
|
params[:select] = columns
|
|
143
145
|
when :update, :delete
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
if params[:where].is_a?(Array)
|
|
147
|
+
path << "/#{params[:where][0]['id']}"
|
|
148
|
+
params[:where][0].delete('id')
|
|
149
|
+
params[:where].shift if params[:where][0].empty?
|
|
150
|
+
else
|
|
151
|
+
path << "/#{params[:where]['id']}"
|
|
152
|
+
params[:where].delete('id')
|
|
153
|
+
params.delete(:where) if params[:where].empty?
|
|
154
|
+
end
|
|
155
|
+
params[:where] = params[:where].first if params[:where]&.one?
|
|
146
156
|
end
|
|
147
157
|
|
|
148
|
-
if params.size > 0
|
|
158
|
+
if params.size > 0
|
|
149
159
|
newpath = path + "?#{CGI.escape(MessagePack.pack(params))}"
|
|
150
160
|
if newpath.length > MAX_URI_LENGTH
|
|
151
161
|
request_type_override = Net::HTTP::Post
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'arel/visitors/visitor'
|
|
2
4
|
|
|
3
5
|
module Arel
|
|
@@ -160,7 +162,6 @@ module Arel
|
|
|
160
162
|
collector.table = o.relation.name
|
|
161
163
|
collector.operation = :update
|
|
162
164
|
|
|
163
|
-
# collector.id = o.wheres.first.children.first.right
|
|
164
165
|
if !o.wheres.empty?
|
|
165
166
|
collector.where = o.wheres.map { |x| visit(x, collector) }.inject([]) { |c, w|
|
|
166
167
|
w.is_a?(Array) ? c += w : c << w
|
|
@@ -171,8 +172,6 @@ module Arel
|
|
|
171
172
|
raise 'Upsupported'
|
|
172
173
|
end
|
|
173
174
|
|
|
174
|
-
collector.where = collector.where.first
|
|
175
|
-
|
|
176
175
|
if o.values
|
|
177
176
|
collector.updates = {}
|
|
178
177
|
|
data/lib/sunstone/connection.rb
CHANGED
data/lib/sunstone/exception.rb
CHANGED
data/lib/sunstone/gis.rb
CHANGED
data/lib/sunstone/version.rb
CHANGED
data/lib/sunstone.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'uri'
|
|
2
4
|
require 'net/http'
|
|
3
5
|
require 'net/https'
|
|
@@ -7,6 +9,7 @@ require 'msgpack'
|
|
|
7
9
|
require 'cookie_store' # optional
|
|
8
10
|
|
|
9
11
|
require "active_record"
|
|
12
|
+
require "active_record/locking/optimistic"
|
|
10
13
|
|
|
11
14
|
# Adapter
|
|
12
15
|
require File.expand_path(File.join(__FILE__, '../sunstone/version'))
|
|
@@ -20,16 +23,21 @@ require File.expand_path(File.join(__FILE__, '../arel/visitors/sunstone'))
|
|
|
20
23
|
require File.expand_path(File.join(__FILE__, '../arel/collectors/sunstone'))
|
|
21
24
|
|
|
22
25
|
# ActiveRecord Extensions
|
|
26
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/base'))
|
|
23
27
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/statement_cache'))
|
|
24
28
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/associations'))
|
|
25
29
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation'))
|
|
26
30
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation/calculations'))
|
|
27
31
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation/query_methods'))
|
|
32
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation/predicate_builder'))
|
|
33
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation/finder_methods'))
|
|
28
34
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/persistence'))
|
|
29
35
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/callbacks'))
|
|
30
36
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/attribute_methods'))
|
|
31
37
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/transactions'))
|
|
32
38
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/associations/collection_association'))
|
|
39
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/associations/has_many_through_association'))
|
|
40
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/locking/optimistic'))
|
|
33
41
|
|
|
34
42
|
require File.expand_path(File.join(__FILE__, '../../ext/active_support/core_ext/object/to_query'))
|
|
35
43
|
|
|
@@ -37,7 +45,7 @@ require File.expand_path(File.join(__FILE__, '../../ext/arel/select_manager'))
|
|
|
37
45
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/eager_load'))
|
|
38
46
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/attributes/empty_relation'))
|
|
39
47
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/select_statement'))
|
|
40
|
-
|
|
48
|
+
|
|
41
49
|
|
|
42
50
|
|
|
43
51
|
ActiveRecord::ConnectionAdapters.register("sunstone", "ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter", "active_record/connection_adapters/sunstone_adapter")
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sunstone
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.
|
|
4
|
+
version: 8.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jon Bracy
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rake
|
|
@@ -184,14 +183,14 @@ dependencies:
|
|
|
184
183
|
requirements:
|
|
185
184
|
- - ">="
|
|
186
185
|
- !ruby/object:Gem::Version
|
|
187
|
-
version:
|
|
186
|
+
version: '8.0'
|
|
188
187
|
type: :development
|
|
189
188
|
prerelease: false
|
|
190
189
|
version_requirements: !ruby/object:Gem::Requirement
|
|
191
190
|
requirements:
|
|
192
191
|
- - ">="
|
|
193
192
|
- !ruby/object:Gem::Version
|
|
194
|
-
version:
|
|
193
|
+
version: '8.0'
|
|
195
194
|
- !ruby/object:Gem::Dependency
|
|
196
195
|
name: msgpack
|
|
197
196
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -240,28 +239,28 @@ dependencies:
|
|
|
240
239
|
requirements:
|
|
241
240
|
- - ">="
|
|
242
241
|
- !ruby/object:Gem::Version
|
|
243
|
-
version:
|
|
242
|
+
version: 9.0.0
|
|
244
243
|
type: :runtime
|
|
245
244
|
prerelease: false
|
|
246
245
|
version_requirements: !ruby/object:Gem::Requirement
|
|
247
246
|
requirements:
|
|
248
247
|
- - ">="
|
|
249
248
|
- !ruby/object:Gem::Version
|
|
250
|
-
version:
|
|
249
|
+
version: 9.0.0
|
|
251
250
|
- !ruby/object:Gem::Dependency
|
|
252
251
|
name: activerecord-filter
|
|
253
252
|
requirement: !ruby/object:Gem::Requirement
|
|
254
253
|
requirements:
|
|
255
254
|
- - ">="
|
|
256
255
|
- !ruby/object:Gem::Version
|
|
257
|
-
version:
|
|
256
|
+
version: 9.0.0
|
|
258
257
|
type: :runtime
|
|
259
258
|
prerelease: false
|
|
260
259
|
version_requirements: !ruby/object:Gem::Requirement
|
|
261
260
|
requirements:
|
|
262
261
|
- - ">="
|
|
263
262
|
- !ruby/object:Gem::Version
|
|
264
|
-
version:
|
|
263
|
+
version: 9.0.0
|
|
265
264
|
description: A library for interacting with REST APIs. Similar to ActiveResource
|
|
266
265
|
email:
|
|
267
266
|
- jonbracy@gmail.com
|
|
@@ -269,15 +268,21 @@ executables: []
|
|
|
269
268
|
extensions: []
|
|
270
269
|
extra_rdoc_files: []
|
|
271
270
|
files:
|
|
271
|
+
- CHANGELOG.md
|
|
272
272
|
- LICENSE
|
|
273
|
+
- README.md
|
|
273
274
|
- ext/active_record/associations.rb
|
|
274
275
|
- ext/active_record/associations/collection_association.rb
|
|
276
|
+
- ext/active_record/associations/has_many_through_association.rb
|
|
275
277
|
- ext/active_record/attribute_methods.rb
|
|
278
|
+
- ext/active_record/base.rb
|
|
276
279
|
- ext/active_record/callbacks.rb
|
|
277
|
-
- ext/active_record/
|
|
280
|
+
- ext/active_record/locking/optimistic.rb
|
|
278
281
|
- ext/active_record/persistence.rb
|
|
279
282
|
- ext/active_record/relation.rb
|
|
280
283
|
- ext/active_record/relation/calculations.rb
|
|
284
|
+
- ext/active_record/relation/finder_methods.rb
|
|
285
|
+
- ext/active_record/relation/predicate_builder.rb
|
|
281
286
|
- ext/active_record/relation/query_methods.rb
|
|
282
287
|
- ext/active_record/statement_cache.rb
|
|
283
288
|
- ext/active_record/transactions.rb
|
|
@@ -307,9 +312,12 @@ files:
|
|
|
307
312
|
- lib/sunstone/gis.rb
|
|
308
313
|
- lib/sunstone/version.rb
|
|
309
314
|
homepage: http://sunstonerb.com
|
|
310
|
-
licenses:
|
|
311
|
-
|
|
312
|
-
|
|
315
|
+
licenses:
|
|
316
|
+
- MIT
|
|
317
|
+
metadata:
|
|
318
|
+
source_code_uri: https://github.com/malomalo/sunstone
|
|
319
|
+
changelog_uri: https://github.com/malomalo/sunstone/blob/master/CHANGELOG.md
|
|
320
|
+
rubygems_mfa_required: 'true'
|
|
313
321
|
rdoc_options: []
|
|
314
322
|
require_paths:
|
|
315
323
|
- lib
|
|
@@ -317,15 +325,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
317
325
|
requirements:
|
|
318
326
|
- - ">="
|
|
319
327
|
- !ruby/object:Gem::Version
|
|
320
|
-
version: '
|
|
328
|
+
version: '3.3'
|
|
321
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
330
|
requirements:
|
|
323
331
|
- - ">="
|
|
324
332
|
- !ruby/object:Gem::Version
|
|
325
333
|
version: '0'
|
|
326
334
|
requirements: []
|
|
327
|
-
rubygems_version:
|
|
328
|
-
signing_key:
|
|
335
|
+
rubygems_version: 4.0.11
|
|
329
336
|
specification_version: 4
|
|
330
337
|
summary: A library for interacting with REST APIs
|
|
331
338
|
test_files: []
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
# The last ref that this code was synced with Rails
|
|
2
|
-
# ref: 9269f634d471ad6ca46752421eabd3e1c26220b5
|
|
3
|
-
|
|
4
|
-
module ActiveRecord
|
|
5
|
-
class PredicateBuilder # :nodoc:
|
|
6
|
-
|
|
7
|
-
def expand_from_hash(attributes, &block)
|
|
8
|
-
return ["1=0"] if attributes.empty?
|
|
9
|
-
|
|
10
|
-
attributes.flat_map do |key, value|
|
|
11
|
-
if key.is_a?(Array) && key.size == 1
|
|
12
|
-
key = key.first
|
|
13
|
-
value = value.flatten
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
if key.is_a?(Array)
|
|
17
|
-
queries = Array(value).map do |ids_set|
|
|
18
|
-
raise ArgumentError, "Expected corresponding value for #{key} to be an Array" unless ids_set.is_a?(Array)
|
|
19
|
-
expand_from_hash(key.zip(ids_set).to_h)
|
|
20
|
-
end
|
|
21
|
-
grouping_queries(queries)
|
|
22
|
-
elsif value.is_a?(Hash) && !table.has_column?(key)
|
|
23
|
-
ka = table.associated_table(key, &block)
|
|
24
|
-
.predicate_builder.expand_from_hash(value.stringify_keys)
|
|
25
|
-
|
|
26
|
-
if self.table.instance_variable_get(:@klass).connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
|
27
|
-
ka.each { |k|
|
|
28
|
-
if k.left.is_a?(Arel::Attributes::Attribute) || k.left.is_a?(Arel::Attributes::Relation)
|
|
29
|
-
k.left = Arel::Attributes::Relation.new(k.left, key)
|
|
30
|
-
end
|
|
31
|
-
}
|
|
32
|
-
end
|
|
33
|
-
ka
|
|
34
|
-
elsif table.associated_with?(key)
|
|
35
|
-
# Find the foreign key when using queries such as:
|
|
36
|
-
# Post.where(author: author)
|
|
37
|
-
#
|
|
38
|
-
# For polymorphic relationships, find the foreign key and type:
|
|
39
|
-
# PriceEstimate.where(estimate_of: treasure)
|
|
40
|
-
associated_table = table.associated_table(key)
|
|
41
|
-
if associated_table.polymorphic_association?
|
|
42
|
-
value = [value] unless value.is_a?(Array)
|
|
43
|
-
klass = PolymorphicArrayValue
|
|
44
|
-
elsif associated_table.through_association?
|
|
45
|
-
next associated_table.predicate_builder.expand_from_hash(
|
|
46
|
-
associated_table.primary_key => value
|
|
47
|
-
)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
klass ||= AssociationQueryValue
|
|
51
|
-
queries = klass.new(associated_table, value).queries.map! do |query|
|
|
52
|
-
# If the query produced is identical to attributes don't go any deeper.
|
|
53
|
-
# Prevents stack level too deep errors when association and foreign_key are identical.
|
|
54
|
-
query == attributes ? self[key, value] : expand_from_hash(query)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
grouping_queries(queries)
|
|
58
|
-
elsif table.aggregated_with?(key)
|
|
59
|
-
mapping = table.reflect_on_aggregation(key).mapping
|
|
60
|
-
values = value.nil? ? [nil] : Array.wrap(value)
|
|
61
|
-
if mapping.length == 1 || values.empty?
|
|
62
|
-
column_name, aggr_attr = mapping.first
|
|
63
|
-
values = values.map do |object|
|
|
64
|
-
object.respond_to?(aggr_attr) ? object.public_send(aggr_attr) : object
|
|
65
|
-
end
|
|
66
|
-
self[column_name, values]
|
|
67
|
-
else
|
|
68
|
-
queries = values.map do |object|
|
|
69
|
-
mapping.map do |field_attr, aggregate_attr|
|
|
70
|
-
self[field_attr, object.try!(aggregate_attr)]
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
grouping_queries(queries)
|
|
75
|
-
end
|
|
76
|
-
else
|
|
77
|
-
self[key, value]
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
module ActiveRecord
|
|
86
|
-
module FinderMethods
|
|
87
|
-
|
|
88
|
-
class SunstoneJoinDependency
|
|
89
|
-
def initialize(klass)
|
|
90
|
-
@klass = klass
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def reflections
|
|
94
|
-
[]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def apply_column_aliases(relation)
|
|
98
|
-
relation
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def instantiate(result_set, strict_loading_value, &block)
|
|
102
|
-
seen = Hash.new { |i, object_id|
|
|
103
|
-
i[object_id] = Hash.new { |j, child_class|
|
|
104
|
-
j[child_class] = {}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
model_cache = Hash.new { |h, klass| h[klass] = {} }
|
|
109
|
-
parents = model_cache[@klass]
|
|
110
|
-
|
|
111
|
-
message_bus = ActiveSupport::Notifications.instrumenter
|
|
112
|
-
|
|
113
|
-
payload = {
|
|
114
|
-
record_count: result_set.length,
|
|
115
|
-
class_name: @klass.name
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
message_bus.instrument("instantiation.active_record", payload) do
|
|
119
|
-
result_set.each { |row_hash|
|
|
120
|
-
parent_key = @klass.primary_key ? row_hash[@klass.primary_key] : row_hash
|
|
121
|
-
parent = parents[parent_key] ||= @klass.instantiate(row_hash.select{|k,v| @klass.column_names.include?(k.to_s) }, &block)
|
|
122
|
-
construct(parent, row_hash.select{|k,v| !@klass.column_names.include?(k.to_s) }, seen, model_cache, strict_loading_value)
|
|
123
|
-
}
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
parents.values
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def construct(parent, relations, seen, model_cache, strict_loading_value)
|
|
130
|
-
relations.each do |key, attributes|
|
|
131
|
-
reflection = parent.class.reflect_on_association(key)
|
|
132
|
-
next unless reflection
|
|
133
|
-
|
|
134
|
-
if reflection.collection?
|
|
135
|
-
other = parent.association(reflection.name)
|
|
136
|
-
other.loaded!
|
|
137
|
-
else
|
|
138
|
-
if parent.association_cached?(reflection.name)
|
|
139
|
-
model = parent.association(reflection.name).target
|
|
140
|
-
construct(model, attributes.select{|k,v| !model.class.column_names.include?(k.to_s) }, seen, model_cache, strict_loading_value)
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
if !reflection.collection?
|
|
145
|
-
construct_association(parent, reflection, attributes, seen, model_cache, strict_loading_value)
|
|
146
|
-
else
|
|
147
|
-
attributes.each do |row|
|
|
148
|
-
construct_association(parent, reflection, row, seen, model_cache, strict_loading_value)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def construct_association(parent, reflection, attributes, seen, model_cache, strict_loading_value)
|
|
156
|
-
return if attributes.nil?
|
|
157
|
-
|
|
158
|
-
klass = if reflection.polymorphic?
|
|
159
|
-
parent.send(reflection.foreign_type).constantize.base_class
|
|
160
|
-
else
|
|
161
|
-
reflection.klass
|
|
162
|
-
end
|
|
163
|
-
id = attributes[klass.primary_key]
|
|
164
|
-
model = seen[parent.object_id][klass][id]
|
|
165
|
-
|
|
166
|
-
if model
|
|
167
|
-
construct(model, attributes.select{|k,v| !klass.column_names.include?(k.to_s) }, seen, model_cache, strict_loading_value)
|
|
168
|
-
|
|
169
|
-
other = parent.association(reflection.name)
|
|
170
|
-
|
|
171
|
-
if reflection.collection?
|
|
172
|
-
other.target.push(model)
|
|
173
|
-
else
|
|
174
|
-
other.target = model
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
other.set_inverse_instance(model)
|
|
178
|
-
else
|
|
179
|
-
model = construct_model(parent, reflection, id, attributes.select{|k,v| klass.column_names.include?(k.to_s) }, seen, model_cache, strict_loading_value)
|
|
180
|
-
seen[parent.object_id][model.class.base_class][id] = model
|
|
181
|
-
construct(model, attributes.select{|k,v| !klass.column_names.include?(k.to_s) }, seen, model_cache, strict_loading_value)
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def construct_model(record, reflection, id, attributes, seen, model_cache, strict_loading_value)
|
|
187
|
-
klass = if reflection.polymorphic?
|
|
188
|
-
record.send(reflection.foreign_type).constantize
|
|
189
|
-
else
|
|
190
|
-
reflection.klass
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
model = model_cache[klass][id] ||= klass.instantiate(attributes)
|
|
194
|
-
other = record.association(reflection.name)
|
|
195
|
-
|
|
196
|
-
if reflection.collection?
|
|
197
|
-
other.target.push(model)
|
|
198
|
-
else
|
|
199
|
-
other.target = model
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
other.set_inverse_instance(model)
|
|
203
|
-
model
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
def apply_join_dependency(eager_loading: group_values.empty?)
|
|
209
|
-
if connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
|
210
|
-
join_dependency = SunstoneJoinDependency.new(base_class)
|
|
211
|
-
relation = except(:includes, :eager_load, :preload)
|
|
212
|
-
relation.arel.eager_load = Arel::Nodes::EagerLoad.new(eager_load_values)
|
|
213
|
-
else
|
|
214
|
-
join_dependency = construct_join_dependency(
|
|
215
|
-
eager_load_values | includes_values, Arel::Nodes::OuterJoin
|
|
216
|
-
)
|
|
217
|
-
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
if eager_loading && has_limit_or_offset? && !(
|
|
221
|
-
using_limitable_reflections?(join_dependency.reflections) &&
|
|
222
|
-
using_limitable_reflections?(
|
|
223
|
-
construct_join_dependency(
|
|
224
|
-
select_association_list(joins_values).concat(
|
|
225
|
-
select_association_list(left_outer_joins_values)
|
|
226
|
-
), nil
|
|
227
|
-
).reflections
|
|
228
|
-
)
|
|
229
|
-
)
|
|
230
|
-
if !connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
|
231
|
-
relation = skip_query_cache_if_necessary do
|
|
232
|
-
klass.connection.distinct_relation_for_primary_key(relation)
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
if block_given?
|
|
238
|
-
yield relation, join_dependency
|
|
239
|
-
else
|
|
240
|
-
relation
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
end
|