eager_group 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/eager_group/preloader.rb +5 -5
- data/lib/eager_group/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f670fdfe6005404593f062ca54f9e415512779
|
4
|
+
data.tar.gz: 2d744e1dfe87edcf0e9e800a33970c443de1a392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7954ec79f25757d438d993395e3a0d17b2409ccd9cc7792886653d1bee8fb22c728924b9ca134aa9509aea7e92e378daf82d85035274efa5ee8e7a4bd7dbc977
|
7
|
+
data.tar.gz: 62412a67a9401bd50ec7ee67c712aaf75010afaffb56a70a64c7eb8e4882f4ff54a7af9fcfb869c6f8d9f6b7bdb229a41a7e5829dbcd16c24af05c7773d90e0a
|
data/CHANGELOG.md
CHANGED
@@ -11,11 +11,11 @@ module EagerGroup
|
|
11
11
|
primary_key = @klass.primary_key
|
12
12
|
record_ids = @records.map { |record| record.send primary_key }
|
13
13
|
@eager_group_values.each do |eager_group_value|
|
14
|
-
|
15
|
-
if definition
|
14
|
+
defination_key, arguments = eager_group_value.is_a?(Array) ? [eager_group_value.shift, eager_group_value] : [eager_group_value, nil]
|
15
|
+
if definition = @klass.eager_group_definations[defination_key]
|
16
16
|
reflection = @klass.reflect_on_association(definition.association)
|
17
17
|
association_class = reflection.class_name.constantize
|
18
|
-
association_class = association_class.instance_exec(&definition.scope) if definition.scope
|
18
|
+
association_class = association_class.instance_exec(*arguments, &definition.scope) if definition.scope
|
19
19
|
polymophic_as_condition = lambda {|reflection|
|
20
20
|
if reflection.type
|
21
21
|
["#{reflection.name}.#{reflection.type} = ?", @klass.base_class.name]
|
@@ -23,7 +23,7 @@ module EagerGroup
|
|
23
23
|
[]
|
24
24
|
end
|
25
25
|
}
|
26
|
-
|
26
|
+
|
27
27
|
if reflection.through_reflection
|
28
28
|
foreign_key = "#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}"
|
29
29
|
aggregate_hash = association_class.joins(reflection.through_reflection.name)
|
@@ -39,7 +39,7 @@ module EagerGroup
|
|
39
39
|
end
|
40
40
|
@records.each do |record|
|
41
41
|
id = record.send primary_key
|
42
|
-
record.send "#{
|
42
|
+
record.send "#{defination_key}=", aggregate_hash[id] || 0
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/eager_group/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eager_group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Fix n+1 aggregate sql functions
|