brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Broken with unique constraint on position #245

Closed mdesantis closed 7 years ago

mdesantis commented 7 years ago

On repositioning (insert_at, etc.) the position gets updated before updating the siblings positions, which conflicts with unique constraint on position column. Also validates_uniqueness_of :position conflicts.

The solution could be not trivial; one possibility could be using temporary negative positions while updating in order to avoid the conflicts.

zharikovpro commented 7 years ago

Very specific option (if supported by DB, like in Postgres) may be to create that constraint with 'deferrable initial deferred' option, and making it nullable. That way constraint check should be postponed till the transaction end, when all positions are unique.

brendon commented 7 years ago

Yes, this has been discussed in another issue. You're right in that it's non-trivial to accommodate. We'll certainly look into any PR's that attempt to solve it in a graceful way :)

brendon commented 7 years ago

Closed by #246