BACKTRACE

(condense)

Back to Posts List

GET

AR eager loading and :select

The AR::Base.find support the options of :include (for adding associations as JOINs in the select) and :select (which pinpoints the columns you wish to select.
For some reason, it is impossible to do them both toghther for example
<br /> Article.find(:all, :include => :author, :select => 'authors.name')<br />
This line will raise an exception.
Luckily, there is the select_with_include gem which enables this feature!

first, install the gem
<br /> gem install select_with_include<br />
next, require it in your environment configuration file (or in environment.rb)
<br /> require 'include_with_select'<br />
Now, you can use the :select option, remembering to use the table name even if a column name is not unique.
There is a single fault back, in case you want to select all the table columns, you need to write them all, one by one. yeah, it sucks.

POST

blog comments powered by Disqus

I Don't have cookies.

ELAD ENV

Variable Value
LINKEDIN
TWITTER
FACEBOOK
GITHUB
WWR
IRC
{ 'irc.freenode.net' => [ '#rubyonrails', '#railsbridge', '#ruby', '#mootools' ]}
SKYPE
eladmeidar

You're seeing this error because I think it is funny.