I am building an application with a database table for games. All games have different attributes, although some attributes are the same for each game, mostly name and type. I store all the attributes in a separate table so that they can be searchable. Every game has a
has_many relationship to attributes.
Table games id int primary key name string unique type string Table attributes id int primary_key game_id int name string value text
For example the game "Nyan Cat Adventures in Space" (made up name) could have the following attributes:
id game_id name value 4 344 dlc 99 5 344 packages 2209 6 344 language "Space Cat" 7 344 dlc 551
I need the attributes to be fully searchable (and indexed). I would like to be able to transform the attributes into a hash so that I could access certain attributes like this:
game.attributes['dlc']. Note however that some attributes can have the same name. What is the best way to achieve this, should I extend ActiveRecord::Base? Is there a function or callback I can use?