Luke Cowell wrote in post #954803:
> At the end of the day, the most important thing is that it works.
> However, I think we should try to get the database do the work. I'll
> apologize in advance that this example is rails2.
>
> # Project -> TaskList -> Task
> Project.all(:group => "projects.id", :joins => {:task_lists => :task},
> :conditions => "tasks.status = 'open'")
>
> This results is a list of projects that have open tasks.
>
> Luke

Thanks a lot, Luke.
This is exactly, what I meant.

Actually, there is next structure:

User -> Project -> Tasklist -> Task

Thanks to Luke, I wrote next scope in the model:

class Project < ActiveRecord::Base
  has_and_belongs_to_many :users
  has_many :tasklists
  belongs_to :user

  def self.active
    all(:group => 'projects.id', :joins => {:tasklists => :tasks}, 
:conditions => "tasks.status = 'open'")
  end
end

And now the call User.first.projects.active returns all the projects 
with active tasks.

Max Reznichenko

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to