active_record-json_associations 0.6.7 → 0.6.8
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: b1d844089bbc9addaaa6680fff31aac70e44ecf8
|
4
|
+
data.tar.gz: 53bacf65b6bbfe4a2e47cc300e88235733e7c20e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e88b1f2079405a05c2b75490845f7c2dc2918110b3aebd977148c9b2f630a22bdec21ca276c75c3c2e20992a2e523b57961af054cc844caa8b27e57c1f7e723
|
7
|
+
data.tar.gz: 98cc39387cfab3b919c44d44e0065d2f5b76fc2f24fc9d72053e6cadbd057f0524d12c744a4f77eac3d9ddcd0bb4153f533fd36682dd955085c8496d28a8a168
|
@@ -25,7 +25,16 @@ module ActiveRecord
|
|
25
25
|
|
26
26
|
define_method many do
|
27
27
|
klass = class_name.constantize
|
28
|
-
klass.
|
28
|
+
scope = klass.all
|
29
|
+
|
30
|
+
ids = send(one_ids)
|
31
|
+
scope.where!(klass.primary_key => ids)
|
32
|
+
|
33
|
+
fragments = []
|
34
|
+
fragments += ["#{klass.primary_key} NOT IN (#{ids.map(&:to_s).join(",")})"] if ids.any?
|
35
|
+
fragments += ids.reverse.map { |id| "#{klass.primary_key}=#{id}" }
|
36
|
+
order_by_ids = fragments.join(", ")
|
37
|
+
scope.order!(order_by_ids)
|
29
38
|
end
|
30
39
|
|
31
40
|
define_method many_equals do |collection|
|
@@ -74,6 +74,11 @@ describe ActiveRecord::JsonAssociations do
|
|
74
74
|
expect(subject.children).to eq children
|
75
75
|
end
|
76
76
|
|
77
|
+
it "finds the children by id order" do
|
78
|
+
subject.child_ids = [3,2,1]
|
79
|
+
expect(subject.children).to eq children.reverse
|
80
|
+
end
|
81
|
+
|
77
82
|
it "is an accessor" do
|
78
83
|
subject.children = children
|
79
84
|
expect(subject.children).to eq children
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-json_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|