Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 12/15/2010: :Include… everything


  • Problem: Select includes “*” by default, so selecting by specific column names does not work

If you write:

class Thing < ActiveRecord::Base
  has_many :posts

class Post < ActiveRecord::Base
  default_scope select(column_names - ['body'])

Thing.includes(:posts).all does the following for the posts query:

SELECT id, fk_column_id, column1, etc, posts.*
FROM posts
WHERE (pages.fk_column>in IN(1,2,3))

It takes the default select scope, but also appends posts.* to the end of it.

This is caused by the :select find_option in the find_associated_records inside of association_preload.rb. This is what it is now:

:select => preload_options[:select]
                || options[:select]

It seems like the third || case is not needed, since that is the default for any select and it causes the above behavior.

Joseph Palermo has filed a ticket with Lighthouse about this…

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *