Skip to content

Instantly share code, notes, and snippets.

@mdarby
Forked from bramhaghosh/gist:1334453
Created November 2, 2011 19:31
Show Gist options
  • Save mdarby/1334638 to your computer and use it in GitHub Desktop.
Save mdarby/1334638 to your computer and use it in GitHub Desktop.
something stupid w/ polymorphic associations
class Deal < ActiveRecord::Base
belongs_to :store
has_many :categories, :as => :categorizable
end
class Store < ActiveRecord::Base
has_many :deals
has_many :categories, :as => :categorizable
has_many :coupons, :through => :categories
end
class Category < ActiveRecord::Base
belongs_to :categorizable, :polymorphic => true
has_many :deals, :through => :categorizable
end
#I want to be able to given a certain category.name, get a list of Deals
#and then given a certain category.name, get a list of Coupons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment