mongoid_orderable 6.0.6 → 6.0.7
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +18 -2
- data/lib/mongoid/orderable/handlers/base.rb +3 -0
- data/lib/mongoid/orderable/mixins/helpers.rb +7 -1
- data/lib/mongoid/orderable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7c9edf55be552b8dfa6fdfa8a11df19801f66696361d567fda9e645d8736674
|
|
4
|
+
data.tar.gz: 579bfbee824451e8d58ca9bddde51bd95b2cb103571c22a9dc6beb045da3af14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a8f4c43964e53a772900978f5a0155ea53bfeffc0cf2775bc10a6db086073adbe855b0bced555abbf4b2a5808c1a92753acaed853783b67ece7f8b2d1520802
|
|
7
|
+
data.tar.gz: d6cb3996dd6577d5cf52eb8fb487fbcb9fffbd5f708074cf1e0e2185e0a44394eb8c23260f019a30802ad79d0d4623c8fa7a30ec82781d6e378d2810e1d5135e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### 6.0.7 (2026/10/18)
|
|
2
|
+
|
|
3
|
+
* [#92](https://github.com/mongoid/mongoid_orderable/pull/92): Fix direct position assignment for embedded documents while retaining the movement API, based on regression tests by [@johnnyshields](https://github.com/johnnyshields) - [@dblock](https://github.com/dblock).
|
|
4
|
+
|
|
1
5
|
### 6.0.6 (2026/10/14)
|
|
2
6
|
|
|
3
7
|
* [#90](https://github.com/mongoid/mongoid_orderable/pull/90): Explicitly load Logger for modern ActiveSupport compatibility.
|
data/README.md
CHANGED
|
@@ -28,10 +28,10 @@ For older versions, please use Mongoid::Orderable 5.x and earlier.
|
|
|
28
28
|
|
|
29
29
|
Transaction support requires MongoDB 4.2+ (4.4+ recommended.)
|
|
30
30
|
|
|
31
|
-
CI tests representative compatible combinations through Ruby 4.0, Mongoid 9, and MongoDB Server 8.0, retaining Ruby 2.6 / Mongoid 7 / MongoDB 4.4 coverage. See [the test matrix](.github/workflows/test.yml); this is not a Cartesian product of supported versions. Every CI test job uses an isolated single-node replica set, so transaction and non-transaction tests both run. Set `MONGOID_VERSION` to select a Mongoid major version and `MONGODB_HOST` to override the default `localhost:27017` when running tests.
|
|
32
|
-
|
|
33
31
|
## Usage
|
|
34
32
|
|
|
33
|
+
See [UPGRADING](UPGRADING.md) for migration notes, including embedded position assignment changes in 6.0.7.
|
|
34
|
+
|
|
35
35
|
### Getting Started
|
|
36
36
|
|
|
37
37
|
```ruby
|
|
@@ -187,6 +187,22 @@ end
|
|
|
187
187
|
To ensure the position is written correctly, you will need to set
|
|
188
188
|
`cascade_callbacks: true` on the relation.
|
|
189
189
|
|
|
190
|
+
Assigning an embedded document's position reorders its siblings when either the child or its parent is saved:
|
|
191
|
+
|
|
192
|
+
```ruby
|
|
193
|
+
survey = Survey.create!
|
|
194
|
+
3.times { survey.questions.create! }
|
|
195
|
+
question = survey.questions.last
|
|
196
|
+
|
|
197
|
+
question.position = 1
|
|
198
|
+
survey.save! # question.save! also works
|
|
199
|
+
survey.reload.questions.map(&:position) # => [2, 3, 1]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Positions below the top or above the bottom are clamped to the list bounds. Assigning `nil` moves an existing child to the bottom. New children with a position are inserted at that position, shifting later siblings. Existing `move_to`, `move_to!`, and their helper methods remain supported; an explicit movement request takes precedence over a direct position assignment.
|
|
203
|
+
|
|
204
|
+
This changes the previous behavior where assigning an existing embedded child's position could leave duplicate positions instead of shifting its siblings. See [UPGRADING](UPGRADING.md).
|
|
205
|
+
|
|
190
206
|
### Disable Ordering
|
|
191
207
|
|
|
192
208
|
You can disable position tracking for specific documents using the `:if` and `:unless` options.
|
|
@@ -60,6 +60,7 @@ module Handlers
|
|
|
60
60
|
set_lock(field) if use_transactions
|
|
61
61
|
|
|
62
62
|
f = orderable_field(field)
|
|
63
|
+
target_position ||= orderable_position(field) || :bottom if embedded? && doc.send("#{f}_changed?")
|
|
63
64
|
scope = orderable_scope(field)
|
|
64
65
|
scope_changed = orderable_scope_changed?(field)
|
|
65
66
|
|
|
@@ -74,6 +75,8 @@ module Handlers
|
|
|
74
75
|
nil
|
|
75
76
|
elsif persisted? && !embedded?
|
|
76
77
|
scope.where(_id: _id).pluck(f).first
|
|
78
|
+
elsif persisted? && embedded?
|
|
79
|
+
doc.send("#{f}_was")
|
|
77
80
|
else
|
|
78
81
|
orderable_position(field)
|
|
79
82
|
end
|
|
@@ -29,7 +29,13 @@ module Mixins
|
|
|
29
29
|
def orderable_bottom(field = nil, in_list = true)
|
|
30
30
|
field ||= default_orderable_field
|
|
31
31
|
f = orderable_field(field)
|
|
32
|
-
|
|
32
|
+
scope = orderable_scope(field)
|
|
33
|
+
scope = scope.ne(_id: _id) if embedded?
|
|
34
|
+
max = scope.ne(f => nil).max(f)
|
|
35
|
+
if embedded? && in_list && persisted?
|
|
36
|
+
previous_position = send("#{f}_was")
|
|
37
|
+
max = [max, previous_position].compact.max
|
|
38
|
+
end
|
|
33
39
|
return orderable_top(field) unless max
|
|
34
40
|
in_list ? max : max.next
|
|
35
41
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid_orderable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.0.
|
|
4
|
+
version: 6.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- pyromaniac
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mongoid
|