named_scope with joins


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments


You need to login to view comments.