Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 12/15/2010: :Include… everything

Phil Goodwin
Wednesday, December 15, 2010

Interesting

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

If you write:

class Thing < ActiveRecord::Base
  has_many :posts
end

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

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]
                || Arel::SqlLiteral.new("#{table_name}.*")

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…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Add New Comment Cancel reply

Your email address will not be published.

Phil Goodwin

Phil Goodwin
San Francisco

Recent Posts

  • “expect errors”
  • Standup 5/3/2012 Time, time and more time
  • Standup 5/2/2012 A hack a day…
Subscribe to Phil's Feed

Author Topics

agile (8)
clang (1)
db (1)
party (1)
rack (1)
ruby (1)
ccrb (3)
events (1)
jasmine (1)
jenkins (1)
open source (1)
ci (1)
database (1)
git (1)
headless (1)
rvm (1)
selenium (1)
shell (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >