Mauro
(Mauro)
May 11, 2012, 11:03am
1
Tell me if this is correct:
I have a Shop, a Bar and OtherShop.
Everyone have a Category.
So I can create a polymorphic association:
Shop has_many :categories, :as => categorization
Bar has_many :categories, :as => categorization
OtherShop has_many :categories, :as => categorization
Category belongs_to :categorization, :polymorphic => true
Is it the same if I do:
Shop has_many :categories
Bar has_many :categories
OtherShop has_many :categories
Category
belongs_to :shop
belongs_to :bar
belongs_to :other_shop
What's the difference using polymorphic?.
11155
(-- --)
May 11, 2012, 12:16pm
2
Msan Msan wrote in post #1060411:
Tell me if this is correct:
I have a Shop, a Bar and OtherShop.
Everyone have a Category.
So I can create a polymorphic association:
Shop has_many :categories, :as => categorization
Bar has_many :categories, :as => categorization
OtherShop has_many :categories, :as => categorization
Category belongs_to :categorization, :polymorphic => true
Is it the same if I do:
Shop has_many :categories
Bar has_many :categories
OtherShop has_many :categories
Category
belongs_to :shop
belongs_to :bar
belongs_to :other_shop
What's the difference using polymorphic?.
It's simple enough for you to try both in a quick prototype and find out
for yourself. Doing it yourself would also make it more clear to you
than us trying to explain it to you.
Besides the answer is right here in this guide: