brendon / acts_as_list

An ActiveRecord plugin for managing lists.

Home Page:http://brendon.github.io/acts_as_list/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does positioning work on nil?

SyedMSawaid opened this issue · comments

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

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.

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