occams-record 0.25.0 → 0.26.0
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d1c4320c6ac238acbb8329b672c5bc487fa14e5
|
4
|
+
data.tar.gz: 38f86e3f7467fa1134b62e6500c25278a7d1be80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be346b9c94d373cec5955b8c0577edbc62b80b74d958b95e3ff4dcf5a768a59192a4fd9938933b50c06185d568a3467428c92fbf5921838ed6ce17a0c183918
|
7
|
+
data.tar.gz: f56c580afb05217f7ce219d53de678dbb8f7e098cdd62ba01557e4ebd42adc8c4dd45817a8d437f9610e840834988becd69f1071add021a727fd67ef8e79752e
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OccamsRecord
|
2
2
|
module EagerLoaders
|
3
3
|
#
|
4
|
-
# Base class for eagoer loading an association.
|
4
|
+
# Base class for eagoer loading an association. IMPORTANT eager loaders MUST remain stateless after initialization!
|
5
5
|
#
|
6
6
|
class Base
|
7
7
|
# @return [String] association name
|
@@ -28,9 +28,10 @@ module OccamsRecord
|
|
28
28
|
# @param query_logger [Array<String>]
|
29
29
|
#
|
30
30
|
def run(rows, query_logger: nil)
|
31
|
-
query(rows) { |
|
31
|
+
query(rows) { |*args|
|
32
|
+
scope = args[0]
|
32
33
|
assoc_rows = Query.new(scope, use: @use, query_logger: query_logger, &@eval_block).run
|
33
|
-
merge! assoc_rows, rows
|
34
|
+
merge! assoc_rows, rows, *args[1..-1]
|
34
35
|
}
|
35
36
|
end
|
36
37
|
|
@@ -11,8 +11,9 @@ module OccamsRecord
|
|
11
11
|
# @yield
|
12
12
|
#
|
13
13
|
def query(rows)
|
14
|
-
|
15
|
-
|
14
|
+
join_rows = fetch_join_rows(rows)
|
15
|
+
assoc_ids = join_rows.map { |row| row[1] }.compact.uniq
|
16
|
+
yield base_scope.where(@ref.association_primary_key => assoc_ids), join_rows if assoc_ids.any?
|
16
17
|
end
|
17
18
|
|
18
19
|
#
|
@@ -20,9 +21,10 @@ module OccamsRecord
|
|
20
21
|
#
|
21
22
|
# @param assoc_rows [Array<OccamsRecord::Results::Row>] rows loaded from the association
|
22
23
|
# @param rows [Array<OccamsRecord::Results::Row>] rows loaded from the main model
|
24
|
+
# @param join_rows [Array<Array<String>>] raw join'd ids from the db
|
23
25
|
#
|
24
|
-
def merge!(assoc_rows, rows)
|
25
|
-
joins_by_id = join_rows
|
26
|
+
def merge!(assoc_rows, rows, join_rows)
|
27
|
+
joins_by_id = join_rows.reduce({}) { |a, join|
|
26
28
|
id = join[0].to_s
|
27
29
|
a[id] ||= []
|
28
30
|
a[id] << join[1].to_s
|
@@ -64,9 +66,7 @@ module OccamsRecord
|
|
64
66
|
# @param rows [Array<OccamsRecord::Results::Row>]
|
65
67
|
# @return [Array<Array<String>>]
|
66
68
|
#
|
67
|
-
def
|
68
|
-
return @join_rows if defined? @join_rows
|
69
|
-
|
69
|
+
def fetch_join_rows(rows)
|
70
70
|
conn = @model.connection
|
71
71
|
join_table = conn.quote_table_name @ref.join_table
|
72
72
|
assoc_fkey = conn.quote_column_name @ref.association_foreign_key
|
@@ -80,7 +80,7 @@ module OccamsRecord
|
|
80
80
|
conn.quote id
|
81
81
|
}
|
82
82
|
|
83
|
-
|
83
|
+
quoted_ids.any? ? conn.
|
84
84
|
exec_query("SELECT #{fkey}, #{assoc_fkey} FROM #{join_table} WHERE #{fkey} IN (#{quoted_ids.join ','})").
|
85
85
|
rows : []
|
86
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: occams-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.5.2.2
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: The missing high-efficiency query API for ActiveRecord
|