mongoid_orderable icon indicating copy to clipboard operation
mongoid_orderable copied to clipboard

BUG: I can't add item in the middle of the list.

Open gotoinc opened this issue 2 years ago • 4 comments

Seems like a bug. Or no functionaly for that. Or i do smth wrong. Steps to reproduce. ``1. rails c

Model

class Test
  ### INCLUDES AND EXTENDS
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Orderable

  orderable field: :position

  ### Fields
  field :rate, type: Integer
  field :position,   type: Integer
end
Test.create!(rate: 80)
Test.create!(rate: 70)
Test.create!(rate: 60)

# Bug
Test.create!(rate: 30, position: 2)
Responce
#<Test _id: 64db673bc9876f69e0f19c91, created_at: 2023-08-15 11:53:27 UTC, updated_at: 2023-08-15 11:53:27 UTC, position: 4, rate: 30>

Help me or I write this functionality by myself.

gotoinc avatar Aug 15 '23 11:08 gotoinc

@dblock @johnnyshields Hey guys. Sorry for pinging directly. It is our team issue. I found an error(or no). Fixed with this commit - we forked and use our repo. I don't know if it's broken, but this patch has solved all our problems. You have more context about the gem and you can say your opinion about that. If you want I can create PR with this changes. I want to be one of open-source contributor)

Commit here(mby it is bad but works, we didn't run the specs). https://github.com/skalibog/mongoid_orderable/commit/c1748108e333a7143dbfbe5f27431e738e34bf1b Have a nice day.

skalibog avatar Aug 15 '23 12:08 skalibog

@skalibog if you want to contribute a fix and a test I'd gladly help merge!

Someone will need to bring back CI first since Travis-CI is RIP, I would copy all GHA from https://github.com/mongoid/mongoid-locker.

dblock avatar Aug 15 '23 21:08 dblock

Fixed by #80

skalibog avatar Oct 24 '23 08:10 skalibog

@gotoinc @skalibog 6.0.5 has been released which fixes this.

Note: if you were using the PR version of #80 please upgrade because it had a slight edge case bug. The bug would occur if you create a new doc, then on the same Ruby object after saving you again changed the position and re-saved it. This case probably doesn't occur in real world apps, because you almost always re-fetch the object in controller actions each time you want to change the position, but just FYI.

johnnyshields avatar Nov 07 '23 17:11 johnnyshields