Thanks a lot!

Frederick Cheung wrote:
> On Feb 20, 10:03�pm, Naija Guy <[email protected]>
> wrote:
>>
>> However, I'm trying to figure out how to search the RoR way based on the
>> role and some other criteria. �For example, if I want to search for all
>> users whose first name is Bob and have a role 'admin', what would I type
>> in the conditions part of the query to filter by role? �I know that with
>> a User.find... query, I can no longer use the "self" keyword to call an
>> instance method.
>>
> You going to have to use a join so that you can have conditions on
> both tables eg
> 
> User.find :all, :joins => :roles, :conditions => ["roles.name = ? AND
> users.name = ? ", 'admin', 'Bob']
> 
> Or you also do it less verbosely by reversing that: Role.find_by_name
> ('admin').users.find :all, :conditions => {:name => 'Bob'}
> 
> Fred

-- 
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