active_record-json_associations 0.6.7 → 0.6.8

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: db8990fae5a00349dbfb5f3fd9066c590126e637
4
- data.tar.gz: cd5fa6ecb84d09a2bc72066dea8f3a133b02d0d3
3
+ metadata.gz: b1d844089bbc9addaaa6680fff31aac70e44ecf8
4
+ data.tar.gz: 53bacf65b6bbfe4a2e47cc300e88235733e7c20e
5
5
  SHA512:
6
- metadata.gz: 8cccd447bcdb4d412e0bcf77fbb2c6ae84497fc7cd34e28993788dd2473ec55ed9b8fb72332186f6612f11e8d4bbd78631d57e22d14527b7e20f4d1b36de3c1b
7
- data.tar.gz: 3800a7453d7046e4a733b54f901dce2e71f88b061309071148c38eb19a0b2acd0394d2435402f464615cfe9997d1a71238ddb628b1efeb7bd660394a5ce6f3cb
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.where(klass.primary_key => send(one_ids))
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|
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JsonAssociations
3
- VERSION = "0.6.7"
3
+ VERSION = "0.6.8"
4
4
  end
5
5
  end
@@ -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.7
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-04-03 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord