Skip to content

Instantly share code, notes, and snippets.

@Breefield
Created November 22, 2013 20:56
Show Gist options
  • Save Breefield/7606749 to your computer and use it in GitHub Desktop.
Save Breefield/7606749 to your computer and use it in GitHub Desktop.
# Type is a :symbol of the model which you want to filter by
def self.filtered_by type
belongs_to type, :foreign_key => :located_id, :foreign_type => type.to_s.capitalize
where(:located_type => type.to_s.capitalize).joins(type).includes(:located)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment