Commit 4280575f authored by DJ Mountney's avatar DJ Mountney
Browse files

Move filtering todos by projects not pending deletion into a scope on the todo model

parent 4ecc10fa
......@@ -23,13 +23,7 @@ def initialize(current_user, params)
end
def execute
items = current_user.todos
# Filter out todos linked to project pending deletion
items = items.joins(
'INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false'
)
items = current_user.todos.not_pending_delete
items = by_action_id(items)
items = by_author(items)
items = by_project(items)
......
......@@ -19,6 +19,7 @@ class Todo < ActiveRecord::Base
scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) }
scope :not_pending_delete, -> { joins('INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false') }
state_machine :state, initial: :pending do
event :done do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment