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

Cannot update record position when scoped to enum #298

Closed Zmokizmoghi closed 6 years ago

Zmokizmoghi commented 6 years ago
class Person < ApplicationRecord
    acts_as_list scope: :position, column: :sort

    enum position: {
        director: 0,
        teacher: 1
    }
end
Person.find(1).move_to_top

fails with

NoMethodError: undefined method `position_id' for #<Person:0x007f88bd86af40>

Ruby version: 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16] Rails version: 5.1.4 Sysytem: OS X 10.13.1

brendon commented 6 years ago

Hi @Zmokizmoghi, have a bit of a dig through the documentation. acts_as_list always appends _id to the scope if you supply a symbol. Supply an array instead [:position]. In saying this, I don't know how you'll get on with your current use case. Using the column name position for starters, and then it being an enum… I guess you can only try :)

Zmokizmoghi commented 6 years ago

Hi @brendon, thanks for explanations, and for this great gem also ;-)

brendon commented 6 years ago

You're welcome :D