_position nil
dudo opened this issue · comments
I can't seem to update the ranking column to nil.
Every attempt to set the column to nil sets a new arbitrary number, as if we were setting the value to 0?
I'd like to remove the rank.
Hi @dudo, I think you'd have to remove the record from the 'scope' that has a ranking. Perhaps operate two scopes that has both a foreign key and also a boolean column on the table that represents in
or out
of the list. The out
's will still have a rank but you don't need to care about that. Hope that makes sense :)
That’s a solution, but why? Why not allow the column to be nil’d out? They start out as nil, since you do so much to ensure there is no default value. Why not let them return to nil?
Would you be opposed to adding a flag to ranks
? ranks :row_order, allow_nil: true
and default it to false? You wouldn't need to do any recalculating, it would seem, either.
#144 is my futile attempt at poking around this. I spent a few hours trying to grok how this might be implemented, but I broke more than I fixed. What do you think?
I'm not opposed to the concept, but the main premise behind ranked-model
is that the rank
column is abstracted away and users should only interact with the _position
pseudo-column. That's why we're trying hard to prevent users giving the column a default value.
I'm happy to look at a PR that implements this, but off the top of my head, I'm thinking this would break a lot of the assumptions we make about the null
value of this column meaning it's a new record being added to the end of the list.
I still think using scopes is the easiest way forward:
scope :in_list, where(in_list: true)
ranks :walking_order, scope: :in_list, with_same: :pond