Hi all, I have a Product with two subclasses, Song and Album. I''d like to have attributes in my Song class that aren''t in my Product or in my Album (like the song duration for example). But if I just put the corresponding field in the DB and let rails handle the attributes, how is it going to work ? I can''t see how it''s going to know that my attribute is supposed to be in the Song class. Sorry if this question has been already asked but I couldn''t find it. And thanks a lot for your answer :) Cheers, Matt. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Francois Beausoleil
2005-Oct-21 17:35 UTC
Re: Inheritance: which attributes belongs to who
Hi ! 2005/10/21, Matthieu Riou <matthieu.riou@gmail.com>:> I have a Product with two subclasses, Song and Album. I'd like to have > attributes in my Song class that aren't in my Product or in my Album (like > the song duration for example). But if I just put the corresponding field in > the DB and let rails handle the attributes, how is it going to work ? I > can't see how it's going to know that my attribute is supposed to be in the > Song class.Doesn't matter. When you have a Song, just treat it as such. When you have an Album, forget about the Song attributes. It's as simple as that. Then again, some attributes of Song you thought you wouldn't need might be useful - Song has a duration, but Album has one too, which is the sum of durations for all songs. Bye ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails