Rails 2.3 using another model's named_scope or alternative

Posted by mustafi on Stack Overflow See other posts from Stack Overflow or by mustafi
Published on 2010-06-15T13:27:29Z Indexed on 2010/06/15 13:42 UTC
Read the original article Hit count: 90

Filed under:

Hi

Let's say I have two models like so:

class Comment < ActiveRecord::Base
  belongs_to :user
  named_scope :about_x :conditions => "comments.text like '%x%')"
end

class User < ActiveRecord::Base
  has_many :comments
end

I would like to use the models so that I can return all the users and all comments with text like '%x%'

all_user_comments_about_x = User.comments.about_x

How to proceed?

Thank you

© Stack Overflow or respective owner

Related posts about ruby-on-rails