Skip to content

Instantly share code, notes, and snippets.

@smathy
Created September 21, 2015 21:26
Show Gist options
  • Save smathy/dc091599444975cf6414 to your computer and use it in GitHub Desktop.
Save smathy/dc091599444975cf6414 to your computer and use it in GitHub Desktop.
class Car
has_many :cross_sections, as: :collectible
end
class Collection
has_many :cross_sections
has_many :collectibles, through: :cross_sections
end
class CrossSection
belongs_to :collectible, polymorphic: true
belongs_to :collection
end
class User
has_many :collections
has_many :favorites, -> { collections.where type: "Favorite" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment