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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bdda82c3c9fc48e48600a93dc0e0983383a91a8
4
- data.tar.gz: dca9174fb3c7ced750dc7408d75d4c121051dec0
3
+ metadata.gz: b33d9c8d9736dc22a9e0dbb1ec004b2d19798ca1
4
+ data.tar.gz: 7cd68b61757df7f42ffcbd77f651391243b61630
5
5
  SHA512:
6
- metadata.gz: 9ce3965debd56f264bea496df1804f7af002db6cf9bfa48c0cc68806f999df062b468af24e66bd4f8d618bf24f5e7de994a7dcc79604c12b2008c10f8247cb6b
7
- data.tar.gz: 4ebafbc03a3ef7a59dc5efb1a89966a22968c26bf01f5a22cbc08c2bdd2797e5fc080cd22917fba981d08dd5e8215dc88de5099c7f3d5d8721438c1f5929c43d
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
- klass = constantize(send(:"#{able}_type"))
32
- klass.where(klass.primary_key => send(:"#{able}_id"))
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[model.send(:"#{able}_type")] ||= {})[model.send(:"#{able}_id")] ||= []) << model
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)
@@ -0,0 +1,11 @@
1
+ module Sequel
2
+ module Plugins
3
+ module Polymorphic
4
+
5
+ VERSION = '0.2.0'
6
+
7
+ end # Polymorphic
8
+ end # Plugins
9
+ end # Sequel
10
+
11
+
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.1.1
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