Skip to content

Instantly share code, notes, and snippets.

@bramhaghosh
Created November 2, 2011 18:33
Show Gist options
  • Save bramhaghosh/1334453 to your computer and use it in GitHub Desktop.
Save bramhaghosh/1334453 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 :coupons
has_many :categories, :as => :categorizable
end
class Category < ActiveRecord::Base
belongs_to :categorizable, :polymorphic => true
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
@bramhaghosh
Copy link
Author

create_table "categories", :force => true do |t|
t.string "name"
t.integer "categorizable_id"
t.string "categorizable_type"
t.datetime "created_at"
t.datetime "updated_at"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment