You know how some bug trackers (and other software) allow you to add custom fields?
Typically this is done with a data structure that looks something like this:
If your intention is to have your FieldDefinition
records belonging to different models (for example, a column item_id
that points to either a SqueekyToyItem
or a BalloonItem
) then what you want is a polymorphic association.
It basically allows you to have an item_type
column (beside your item_id
column), which then specifies the actual type of item it points to.
There's a heading “Polymorphic associations” in the documentation for ActiveRecord::Associations::ClassMethods.