# Using Active Record find

**URL:** <https://www.ruby-forum.com/t/using-active-record-find/86227>\
**Category:** Rails\
**Created:** [February 20, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/using-active-record-find/86227 "2007-02-20T20:25:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [February 20, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/using-active-record-find/86227/1 "2007-02-20T20:25:52Z")

</div>

Hello everybody…

I’m just getting started with Rails and am stuck. I have two tables, a  
user table and a web table.

User \< ActiveRecord::Base  
has\_many :groups

Group \< ActiveRecord::Base  
belongs\_to :user

I’m trying do do a look up to see if a particular user is already part  
of a group. The code I have works but it seems there should be an esier  
way to do it.

if Group.find(:first, :conditions =\> {:user\_id =\>  
User.find\_by\_email(params[:email]), :web\_id =\> session[:web\_id]})

Thanks for any help

- Mark

---

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [February 20, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/using-active-record-find/86227/2 "2007-02-20T21:08:57Z")

</div>

> User \< ActiveRecord::Base  
> has\_many :groups
> 
> Group \< ActiveRecord::Base  
> belongs\_to :user
> 
> I’m trying do do a look up to see if a particular user is already part  
> of a group.

Use the user has\_many groups association to check if a user has any  
groups.

user = User.find\_by\_email(email)  
user.groups.blank?

Aaron
