Adding Conditions to Nested Includes

3 views
Skip to first unread message

gurenski

unread,
Sep 6, 2008, 12:17:23 PM9/6/08
to Envycasts Discussion
The screencast mentions that in Rails 2.1 nested includes are
"cleaner" and contain less fail. It goes on to say that this is not
the case for conditions on a nested include. So, what's the best way
to add a condition on a nested include?

Thanks!

Gregg Pollack

unread,
Sep 6, 2008, 12:28:44 PM9/6/08
to envycasts-...@googlegroups.com
Here is what comes to mind, let me know if anyone else has any ideas.

1. Make sure you have all the foreign keys you need to speed up the query.

2. Use "joins", instead of "includes" if you don't need to instantiate
the included table. i.e ":joins => :users" joins the user table and
allows you to do conditionals on the users table, without loading all
the user objects.

3. You can also use :select if you want to limit the data returned.

4. Write a custom sql query.

Reply all
Reply to author
Forward
0 new messages