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

Does positioning work on nil? #412

Closed SyedMSawaid closed 3 months ago

SyedMSawaid commented 1 year ago

I have this situation where a Todo is scoped by its parent and its project.

But if the parent is null, suppose it is the root node. It wont' position it.

Am I doing something wrong?

class Todo < ApplicationRecord
  has_many :children, class_name: 'Todo', foreign_key: 'parent_id'
  belongs_to :parent, class_name: 'Todo', optional: true
  belongs_to :project
  has_one :sprint_todo
  has_one :sprint, through: :sprint_todo

  recursive_tree
  acts_as_list scope: [:project, :parent]
end
brendon commented 1 year ago

That should work well enough. I'm doing exactly that except with the ancestry gem. Items at the root have a NULL ancestry column. Admittedly I only ever have one root so perhaps it doesn't really work :) I've checked the database and it indeed has a position value so I'm pretty sure it works. You might need to do some more debugging with the logs to trace the SQL that's getting executed.

brendon commented 3 months ago

Do you still need help? I'll close this for now. Feel free to reopen it.