Posted By

nflamel on 03/10/10


Tagged

rails joins namedscope


Versions (?)

named_scope with joins


 / Published in: Rails
 

  1. class Post < ActiveRecord::Base
  2. has_many :comments
  3. named_scope :commented_by, lambda { |user_id| { :joins => :comments, :conditions => ["comments.user_id = ?", user_id] } }
  4. end
  5.  
  6. class Comment < ActiveRecord::Base
  7. belongs_to :user
  8. belongs_to :post
  9. end

Report this snippet  

You need to login to post a comment.