Move filtering todos by projects not pending deletion into a scope on the todo model
This commit is contained in:
parent
4ecc10fade
commit
4280575fc0
2 changed files with 2 additions and 7 deletions
|
@ -23,13 +23,7 @@ class TodosFinder
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
items = current_user.todos
|
items = current_user.todos.not_pending_delete
|
||||||
|
|
||||||
# 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 = by_action_id(items)
|
items = by_action_id(items)
|
||||||
items = by_author(items)
|
items = by_author(items)
|
||||||
items = by_project(items)
|
items = by_project(items)
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Todo < ActiveRecord::Base
|
||||||
|
|
||||||
scope :pending, -> { with_state(:pending) }
|
scope :pending, -> { with_state(:pending) }
|
||||||
scope :done, -> { with_state(:done) }
|
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
|
state_machine :state, initial: :pending do
|
||||||
event :done do
|
event :done do
|
||||||
|
|
Loading…
Reference in a new issue