I'm building a task list app in rails which allows user to create task lists which contain tasks. I am trying set up filtering so I can display only task lists that have all of it's tasks marked as complete.
Currently:
List model:class List < ActiveRecord::Base
belongs_to :user
has_many :tasks
end
Task model:
class Task < ActiveRecord::Base
belongs_to :list
def completed?
!completed_at.blank?
end
end
As I understand it, ActiveRecord's .where query method only looks at at that model's fields and it's value (e.g: @lists.where(name: "List Name"))
Does anyone know a way of doing something similar to the pseudo code below:
@completed_lists = @lists.where(list.tasks.completed.count == list.tasks.count)
Thanks