Topic: Q: How do I refine a result from a find.

Q: I want to find Users who belong to a group and I want to know the groups name.

I can write it in SQL but I'm having difficulty doing it in RoR.

Model:

users
belongs_to :group

groups
has_many :users


Now, very easily I can find the group id of a user from the users table.  But I want the group name.

So far I have the following code

usr = User.find(:all)

Which only gives me the user.group_id.  How do I get the group name from the related table?

Thanks,
beforum

Re: Q: How do I refine a result from a find.

usr = User.find(:all, :include => 'groups')

Or with your original code:
user.group.name #or whatever the group name field is called

vinnie - rails forum admin

Re: Q: How do I refine a result from a find.

Great, that worked.  Except I had to make 'groups' singular. 

usr = User.find(:all, :include => 'group')

Thanks!!!