Forum: Ruby on Rails query

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2008-12-16 03:52
Hi..
Actually i need to get

User's name
Contact's name and it's department id and it's  Authority id and
authority name.
so i done following query.
but its so long.
I don't know about join queries.
so pls help me how can i implemend join query instead of below query....

user = UserInfo.find_by_id(user_id)

=>Using this query  I get user.first_name

contact = UserInfo.find_by_id(contact_id)

=>Using this query  I get contact.first_name and contact.department_id

authority = PrivilegeInfo.find(:first, :conditions => [ "user_id =? and
department_id =? ", contact_id,contact.department_id])

=>Using this query  I get authority.authority_id

authority_name = UserInfo.find_by_id(authority.authority_id)

=>Using this query  I get authority_name.first_name



Thanks in advance
This topic is locked and can not be replied to.