# Eager loading has\_many through

**URL:** <https://www.ruby-forum.com/t/eager-loading-has-many-through/196584>\
**Category:** Rails\
**Created:** [January 29, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/eager-loading-has-many-through/196584 "2008-01-29T23:59:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 29, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/eager-loading-has-many-through/196584/1 "2008-01-29T23:59:21Z")

</div>

hi all,

My relationships:

- group habtm user and
- user has\_many events :through statistics.  
The statistics contains the id of user and is of event and additional  
data.

How can I get all the users in a group with their statistics via eager  
loading.

I tried:  
@users = a\_node.users.find(:all, :include =\> :statistics, :conditions  
=\> [“statistics.event\_id = ?”, event.id])

The problem is that I only get the users with a statistics record and  
I also want users without any stastics. I think the problem is caused  
by :conditions =\> [“statistics.event\_id = ?”, event.id] but I don’t  
know how to include the event\_id in another way.

Someone can help me out?

Thanks  
-Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 30, 2008, 12:01am UTC](https://www.ruby-forum.com/t/eager-loading-has-many-through/196584/2 "2008-01-30T00:01:42Z")

</div>

:include =\> [:statistics, :events] or :include =\> “:statistics, :events”

No?

On Jan 30, 2008 9:28 AM, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> loading.  
> Someone can help me out?
> 
> Thanks  
> -Stijn
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.
