Created
February 17, 2011 22:47
-
-
Save dpickett/832907 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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