Search code examples
ruby-on-railsrubyhas-manyhas-many-throughhas-many-polymorphs

Has_many for different classes


Here is the thing.

I'm working on a web game just for learning and I have this problem.

I have a Character who has many items, but the items can be equipable_items or usable_items (both from different clases).

Is there a way to have a has_many in my Character class to have a bag of items of both clases together?


Solution

  • Yes, check out Single Table Inheritance. You can do a has_many association to the parent class.

    EDIT: Also check out the Single Table Inheritance section in the API documentation.