eager_group 0.2.1 → 0.3.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
2
  SHA1:
3
- metadata.gz: 574a83970abfdabb0e4cdea2d51d9e5aa1b3bb3c
4
- data.tar.gz: f4e26984d00bb20871dbe0ebfd85cf61e62a06e0
3
+ metadata.gz: 0628b41e3191da5216f80c436de1da7c4a9dc3be
4
+ data.tar.gz: 36de11cb727b029633f41cac0950f1fa31a33adc
5
5
  SHA512:
6
- metadata.gz: 5689ebf16a02bd8fe8c92befed8d9f43ebf98b3084196a881f416632f72148b24ca1fa910de5dbd6d3589a287f6dd4c1b7289d3eed8b22f8cd9d588c478119c9
7
- data.tar.gz: 7dfa7ddbaeae8f8ea92bac78c5b2baad996920f73e0011de7daef72751627472b77b51d256a623541cbe4df7cbfe8b8a6e6d5ae23844c85a49f2b55e3d92d0f3
6
+ metadata.gz: efbadb72bff4d8b62e75db9bafaed9d6f4f3197447f35e6bd722ce26977318bf38bf003db102bf973f2c42037c21a57ef06c00a33ebfa4f79f25efe853de516c
7
+ data.tar.gz: 7bec44884ab2c31e914400d9bd370f8de5c7c31c8764b95ec8f907090f4a7a3a589a162527faed42d13608bdb409b5a80d87562d6d2b56e3091dfe3c12e3d674
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Next Release
2
2
 
3
+ ## 0.3.0 (10/11/2015)
4
+
5
+ * Support polymorphic association
6
+
3
7
  ## 0.2.0 (07/11/2015)
4
8
 
5
9
  * Add support to `has_many :through`
@@ -16,14 +16,24 @@ module EagerGroup
16
16
  reflection = @klass.reflect_on_association(definition.association)
17
17
  association_class = reflection.class_name.constantize
18
18
  association_class = association_class.instance_exec(&definition.scope) if definition.scope
19
+ polymophic_as_condition = lambda {|reflection|
20
+ if reflection.type
21
+ ["#{reflection.name}.#{reflection.type} = ?", @klass.base_class.name]
22
+ else
23
+ []
24
+ end
25
+ }
26
+
19
27
  if reflection.through_reflection
20
28
  foreign_key = "#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}"
21
29
  aggregate_hash = association_class.joins(reflection.through_reflection.name)
22
30
  .where("#{foreign_key} IN (?)", record_ids)
31
+ .where(polymophic_as_condition.call(reflection.through_reflection))
23
32
  .group("#{foreign_key}")
24
33
  .send(definition.aggregate_function, definition.column_name)
25
34
  else
26
35
  aggregate_hash = association_class.where(reflection.foreign_key => record_ids)
36
+ .where(polymophic_as_condition.call(reflection))
27
37
  .group(reflection.foreign_key)
28
38
  .send(definition.aggregate_function, definition.column_name)
29
39
  end
@@ -1,3 +1,3 @@
1
1
  module EagerGroup
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eager_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang