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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7cfd1cc8c6993a35a44e4a103d3313005a1064
|
4
|
+
data.tar.gz: 480166d6d9dab02b0f7b37c2fa8a83e2bdb7c173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9516148ab0feaaa0fa7b479a8537433edc2f1ff6aa79a18a6c35ddd84df6407410b04fa829c17cfbaca65060a019646af03c673dbc701c4c8d9a08fb8b1653e6
|
7
|
+
data.tar.gz: b67c141cbd15fd88597fded87da325ff427a235e9b48ab5e6dfab2785319a7772132bc9017db61ba70be336ce57b8ec485b50e5d3ae0df1a207064c96ec02c2d
|
@@ -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
|
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(
|