Sometuink like this can work??
has_one :set_media_data
def set_media_data
case self.media_type
when: ''gallery''
self.data = GalleryData.find(:first, :conditions =>
"media_id = #{self.id}")
when: ''article''
self.data = ArticleData.find(:first, :conditions =>
"media_id = #{self.id}")
when: ''image''
self.data = ImageData.find(:first, :conditions =>
"media_id = #{self.id}")
when: ''music''
self.data = MusicData.find(:first, :conditions =>
"media_id = #{self.id}")
when: ''video''
self.data = VideoData.find(:first, :conditions =>
"media_id = #{self.id}")
end
end
Pedro Valentini escreveu:
> Hi,
> I have the models:
> Media, and have 5 types of medias: Gallery, Article, Image, Music and
> Video.
> Actualy I consider all Media, but now I''m trying to improove the
> system and use this tables:
> medias, gallerys, articles, images, musics and videos
>
> In rails book Daivid sad to not generalize (extends) and use
> association, so how I make it:
> Media has_one :gallery or :article or :image or :music or :video
> It is possible???
> What is the better solution??
>
> ps.: each type of media belongs_to :media
>
> Thank you
>
--
Pedro C. Valentini
pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
+55 (21) 8708-8035