Nested :throughs

Why not just have an extra field in the Task model called completed
(boolean). Next, create a method in the Task model that looks something
like this:

def tasks_completed_by_user(user)
  find(:all, :conditions => {"user_id = '#{user}'", "completed = '1'")

That would give you a collection of Tasks that are marked completed.

Now I am a ROR newbie so the code above may need some tweaking... but
you get the idea.

Dan Hixon wrote:

I'm with Melvin. Ideally, an object/entity shouldn't change its class/
table just because its state has changed.


Thanks for the replies Mark and Melvin.

Since the tasks can indirectly belong to many users at once I couldn't
simply add a completed boolean to that class. ("Run a mile under 6
minutes" might be completed by Jeremy but not yet by Alex).

I ended up adding this method to my user model:

def completed_tasks_in_current_award
    tasks = []
    completed_tasks.each do |ct|
      if ct.task.task_group.award == award
        tasks << ct.task

I'm guessing there might be a way to do it with more code - but this
will suffice for now.