# Using find with multiple objects in active record

**URL:** <https://www.ruby-forum.com/t/using-find-with-multiple-objects-in-active-record/56561>\
**Category:** Rails\
**Created:** [April 1, 2006, 4:08am UTC](https://www.ruby-forum.com/t/using-find-with-multiple-objects-in-active-record/56561 "2006-04-01T04:08:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshibot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7ab992/32.png) [@yoshibot](https://www.ruby-forum.com/u/yoshibot)\
**Post date:** [April 1, 2006, 4:08am UTC](https://www.ruby-forum.com/t/using-find-with-multiple-objects-in-active-record/56561/1 "2006-04-01T04:08:58Z")

</div>

Hi,

I am trying to learn to use RoR by making a simple social networking  
example. Given a user id, I am trying to make a query that finds all of  
the group that user belongs to but also rank the groups by one of the  
groups’ parameter like group.size. Pretend group.size is a number from  
1-10 and is precalculated. Can I do this is one query? Here are the  
relationships I set up:

class User \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :groups  
end

class Groupship \< ActiveRecord::Base  
set\_table\_name “users\_groups”  
belongs\_to :recipes  
belongs\_to :tags  
end

class Group \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :users  
end

Thanks!

---

<div class="post-metadata">

**Author:** ![yoshibot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7ab992/32.png) [@yoshibot](https://www.ruby-forum.com/u/yoshibot)\
**Post date:** [April 1, 2006, 9:02am UTC](https://www.ruby-forum.com/t/using-find-with-multiple-objects-in-active-record/56561/2 "2006-04-01T09:02:48Z")

</div>

This should do it.

groups = user.groups.find(:all,:order =\> ‘size’)

–  
– Tom M.
