Created
November 2, 2011 18:33
-
-
Save bramhaghosh/1334453 to your computer and use it in GitHub Desktop.
something stupid w/ polymorphic associations
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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