active_record-json_associations 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67f879bede0474e8a73e798f7f4facf1370f2d98
4
- data.tar.gz: 17f1a8d6d4654a93fb2bdeb373b1a44e3d9bf21c
3
+ metadata.gz: de7cfd1cc8c6993a35a44e4a103d3313005a1064
4
+ data.tar.gz: 480166d6d9dab02b0f7b37c2fa8a83e2bdb7c173
5
5
  SHA512:
6
- metadata.gz: 2830b22a574bcc27a058ec51f0a7d39f9429c5211ca42b5373edd3b6cc9e10eaa986b9c0d5279275b0624bcd97c9efc5a75ef8f96e92224ed66f3bea7a137a27
7
- data.tar.gz: abf5a10b7af2e76d2d5ff0e2edd3357d3e22adee309291262630fb8801ab0b7a60b7163680cdc20e48a111dc730e8ef5769b7250ca4223ae7c2cf50ab214f95f
6
+ metadata.gz: 9516148ab0feaaa0fa7b479a8537433edc2f1ff6aa79a18a6c35ddd84df6407410b04fa829c17cfbaca65060a019646af03c673dbc701c4c8d9a08fb8b1653e6
7
+ data.tar.gz: b67c141cbd15fd88597fded87da325ff427a235e9b48ab5e6dfab2785319a7772132bc9017db61ba70be336ce57b8ec485b50e5d3ae0df1a207064c96ec02c2d
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JsonAssociations
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -7,10 +7,11 @@ module ActiveRecord
7
7
  one = many.to_s.singularize
8
8
  one_ids = :"#{one}_ids"
9
9
  one_ids_equals = :"#{one_ids}="
10
- class_name ||= one.classify
11
10
  many_equals = :"#{many}="
12
11
  many_eh = :"#{many}?"
13
12
 
13
+ class_name ||= one.classify
14
+
14
15
  serialize one_ids, JSON
15
16
 
16
17
  include Module.new {
@@ -19,7 +20,8 @@ module ActiveRecord
19
20
  end
20
21
 
21
22
  define_method many do
22
- class_name.constantize.where(id: send(one_ids))
23
+ klass = class_name.constantize
24
+ klass.where(id: send(one_ids))
23
25
  end
24
26
 
25
27
  define_method many_equals do |collection|
@@ -43,14 +45,13 @@ module ActiveRecord
43
45
  end
44
46
 
45
47
  one = many.to_s.singularize
46
- class_name ||= one.classify
47
- klass = class_name.constantize
48
-
49
48
  one_ids = :"#{one}_ids"
50
49
  one_ids_equals = :"#{one_ids}="
51
50
  many_equals = :"#{many}="
52
51
  many_eh = :"#{many}?"
53
52
 
53
+ class_name = options[:class_name] || one.classify
54
+
54
55
  foreign_key = options[:json_foreign_key]
55
56
  foreign_key = :"#{model_name.singular}_ids" if foreign_key == true
56
57
 
@@ -60,10 +61,12 @@ module ActiveRecord
60
61
  end
61
62
 
62
63
  define_method one_ids_equals do |ids|
64
+ klass = class_name.constantize
63
65
  send many_equals, klass.find(ids)
64
66
  end
65
67
 
66
68
  define_method many do
69
+ klass = class_name.constantize
67
70
  klass.where("#{foreign_key} LIKE '[#{id}]'").or(
68
71
  klass.where("#{foreign_key} LIKE '[#{id},%'")).or(
69
72
  klass.where("#{foreign_key} LIKE '%,#{id},%'")).or(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-json_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel