FRail :include

I really like developing with Rails, but I've been frustrated the last few days by some things Rails should do quite easily, yet doesn't. I've already written here and here about some of my struggles with Rails :include clause. Here's one more...

Let's say you have a has-and-belongs-to-many relationship. If you :include this relationship in a find query, Rails will automatically create the join clause including the lookup table! That's cool.

Unfortunately, it looks as if only the :include clause provides this piece of functionality. Why isn't the same functionality provided via the :join clause or through a general purpose module? This doesn't make any sense to me!

I'm working on a database application where I don't need to display a lot of data, but the data displayed is heavily filtered by it's connections to other information in the database. I need to join a lot of tables to perform the filtering operation and using :include would be the most elegant way to express my queries. But to :include all the data from the join tables in the response kills the performance of my application (because :select is ignored).

Oh well. It's back to hand coding queries for me. At least until the powers that be agree this is much needed functionality (or someone creates a cool plugin I can use).

Comments

Vinnie said…
I've just installed a Ruby gem called
select_with_include
which allows users to override select!

It unfortunately does not work with
Squirrel
but hey, I'll take what I can get.
Vinnie said…
I was also informed of an "include with select" plugin available here

This one allows you to specify operations in the select clause. I need to play with it more, but I was having problems getting that to work with :limit and :group. Other than that, very helpful.
Vinnie said…
here's another approach...
http://dev.rubyonrails.org/ticket/7147#comment:12

Popular posts from this blog

I Believe...

Performance Tuning JCAPS - Part 2