Forum: Ruby on Rails query

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Newb N. (Guest)
on 2008-12-16 04:52
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.