sequel_polymorphic 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sequel_polymorphic/sequel_polymorphic.rb +8 -3
- data/lib/sequel_polymorphic/version.rb +11 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b33d9c8d9736dc22a9e0dbb1ec004b2d19798ca1
|
4
|
+
data.tar.gz: 7cd68b61757df7f42ffcbd77f651391243b61630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa4aaf04d0abd80335cbf534f4c2e43c2bd4abb5dfcfa9bed3bd45e229760aef1616011c61835ef1bfe40b90f227a43776b623476318c092579325556ecf9253
|
7
|
+
data.tar.gz: 0d693242a54854001494181e8b1d1d53bd0f93ce8a989e60f170d9853b074e8dfdcfb565fc9e7f2d3be443332426214b241ef9ce006c538b7716455c1a0cbca6
|
@@ -28,14 +28,19 @@ module Sequel
|
|
28
28
|
self[:"#{able}_type"] = (able_instance.class.name if able_instance)
|
29
29
|
end),
|
30
30
|
:dataset => (proc do
|
31
|
-
|
32
|
-
|
31
|
+
able_type = send(:"#{able}_type")
|
32
|
+
able_id = send(:"#{able}_id")
|
33
|
+
return if able_type.nil? || able_id.nil?
|
34
|
+
klass = constantize(able_type)
|
35
|
+
klass.where(klass.primary_key => able_id)
|
33
36
|
end),
|
34
37
|
:eager_loader => (proc do |eo|
|
35
38
|
id_map = {}
|
36
39
|
eo[:rows].each do |model|
|
40
|
+
model_able_type = model.send(:"#{able}_type")
|
41
|
+
model_able_id = model.send(:"#{able}_id")
|
37
42
|
model.associations[able] = nil
|
38
|
-
((id_map[
|
43
|
+
((id_map[model_able_type] ||= {})[model_able_id] ||= []) << model if !model_able_type.nil? && !model_able_id.nil?
|
39
44
|
end
|
40
45
|
id_map.each do |klass_name, id_map|
|
41
46
|
klass = constantize(klass_name)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_polymorphic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Dempsey
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- lib/sequel_polymorphic.rb
|
71
71
|
- lib/sequel_polymorphic/sequel_polymorphic.rb
|
72
|
+
- lib/sequel_polymorphic/version.rb
|
72
73
|
homepage: https://github.com/jackdempsey/sequel_polymorphic
|
73
74
|
licenses:
|
74
75
|
- MIT
|