Sure Mauricio, here's an example.
Lets say you have a "products" table. You have product_type table column
in that table that you use for single table inheritance. So lets say you
have the value "book" as the product_type.
Now you want to have a pricing for this product, so you do:
belongs_to :pricing, :polymorphic => true
So now you need a pricing_type with a class name of "BookPricing", or in
other words "#{product_type.classify}Pricing". You will always follow
this convention since I wouldnt have BookPricing for a product_type of
"poster"
But wait! There's more. Now I want another polymorphic association for
"details" for that product. So I do:
belongs_to :detail, :polymorphic => true
So, now I need a "detail_type" column of "BookDetail" or in other words
"#{product_type.classify}Detail".
Now I have two extra string columns that are not needed and are making
things much less DRY.
Aryk
Maurício Linhares wrote:
> On Tue, Oct 7, 2008 at 11:38 PM, Aryk Grosz <
> [EMAIL PROTECTED]> wrote:
>
>> Also, I'd have to add a "_type" column even though you could infer the
>> classname based off another column, thus making things anything but DRY.
>>
>>
>>
> Could you explain this a little bit more?
>
> I guess i don't get the idea you're trying to reach here. How could you
> infer the classname based on another column without having the classname
> in
> that other column?
>
> --
> Maurício Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
> João Pessoa, PB, +55 83 8867-7208
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---