Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created February 17, 2011 22:47
Show Gist options
  • Select an option

  • Save dpickett/832907 to your computer and use it in GitHub Desktop.

Select an option

Save dpickett/832907 to your computer and use it in GitHub Desktop.
Item.with_extended_attributes.order("created_at")
class Item < ActiveRecord::Base
has_one :car_attributes
has_one :dvd_attributes
def self.with_extended_attributes
#you could use some association introspection to build the list of includes
associations = [:dvd_attributes, :car_attributes]
includes(associations.map{|i| "LEFT JOIN #{i} ON items.id = #{i.to_s.tableize}.id"}.join(" "))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment