I am toying with a new project and have a schema design question.
I have a tree-like node structure. Each of the nodes will be
associated with a single object. This associated object can be of a
variety of types.
I represent the tree through a Node class which acts_as_tree. Now
imagine three other classes–Animals, Fruits and Vegetables. Each
node will have an association with one object of ONE type. The object
types are different enough to make STI impractical.
I am thinking of the following: adding a table called associations
and holding three columns–node_id, associated_type, associated_id.
class Node < AR::B
class Association < AR::B
A method of the Association class will pull up the necessary Animal,
Fruit or Vegetable, depending on the associated_type and
associated_id. A method of the Node class will request the actual
associated object from the association itself.
Any thoughts on this?
Many thanks in advance for any ideas,