Forum: Ruby on Rails polymorph without extra tables?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tyler MacDonald (Guest)
on 2007-04-22 03:22
(Received via mailing list)
Here's what I want, and the answer isn't obvious to me :-(

  Widget.Find(id)

    - if the found widget is a "Hammer", I want the model
      object returned to be a Widget::Hammer

    - if the found widget is a "Nail", I want the model
      object returned to be a Widget::Nail

I don't need to store any additional attributes, I just want different
behaviour on the model based on whether my widget is a Hammer or a Nail.
How
is this done? Is this something rails can do? Or will I have to override
some method and inject my own subclass-finding logic in there?

  Thanks,
    Tyler
This topic is locked and can not be replied to.