TLDR: Is there a way to scope acts_as_list into another table as such
class SprintTodo < ApplicationRecord
belongs_to :sprint
belongs_to :todo
acts_as_list scope: [:sprint, :todo.status]
end
I have two tables with one joining table.
Todo(name, position, status, parent, children, ...)SprintTodo(todo_id, sprint_id, position)Sprint(name, start_date, end_date, ...)
Todo has its own position based on its parents (tree) while SprintTodo holds the position as in Kanban Board based on its status.
The problem I am facing right now is that I cannot reach into Todo table to scope it that way. One solution (although a bad one) is to replicate Todo status in SprintTodo as well but that would be bad design.
Is there any other way I can scope it on status?
It'll probably be simpler to add a status column to
SprintTodoinstead. But there is a way:https://www.rubydoc.info/gems/acts_as_list/0.8.2/ActiveRecord/Acts/List/ClassMethods#acts_as_list-instance_method
Update
I didn't see anything in acts_as_list code to support reordering on status change. The change happens in
Todo, but all the callbacks to update position are inSprintTodo:https://github.com/brendon/acts_as_list/blob/v1.1.0/lib/acts_as_list/active_record/acts/callback_definer.rb#L6-L16
First approach is just create a new
SprintTodo:The other way is to trigger some of those callbacks manually:
Have to set
@scope_changed, otherwisecheck_scopewon't do anything:https://github.com/brendon/acts_as_list/blob/v1.1.0/lib/acts_as_list/active_record/acts/list.rb#L430-L441