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
  • Tools
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

03/13/13: [SF] Use postgres!

David Stevenson
Wednesday, March 13, 2013

Helps

eager-loading nested polymorphic associations

We have a controller action that performs n+1 queries to present associated models as nested hashes. The typical solution is to use :include to eager-load associations. Unfortunately, the models are related polymorphically, and :include can’t eager-load nested polymorphic associations. What can we do?

Interestings

Use postgres!

Because in rails it automatically puts a transaction around for DDL statements and rolls them back when things don’t work. Fixing this in mysql can be a huge pain.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

One comment

  1. Kieran P says:

    Regarding the eager loading issue, I tend to do this (say a Comment has a Post or Page polymorphically):

    @comments = Comment.all
    Post::Preloader.new(@comments.select { |c| c.commentable_type == ‘Post’ }, :author)
    Page::Preloader.new(@comments.select { |c| c.commentable_type == ‘Page’ }, :designer)

    It’s ugly, but it works.

    March 13, 2013 at 11:11 pm

Add New Comment Cancel reply

Your email address will not be published.

David Stevenson

David Stevenson
San Francisco

Recent Posts

  • Standup for 2/9/2012: NP in P time? As usual, no.
  • Standup 2/6/2012: Tracker UI updates
  • Standup for 5/13/2011: requiring yaml and psyche, order matters
Subscribe to David's Feed

Author Topics

agile (10)
devise (1)
ec2 (1)
engines (1)
ios (1)
activerecord (3)
inverse_of (1)
css (2)
engineyard (1)
iphone (3)
rubymine (1)
rails (5)
aws (1)
javascript (1)
xmpp (1)
gogaruco (3)
activeresource (1)
heroku (1)
solr (1)
bug (1)
patch (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Tools
  • 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 >