I have a Contract class, along the lines of:
class Contract < ActiveRecord::Base
One or more Conditions might apply to a Contract. Each Condition
imposes some kind of restriction or rule on the Contract it applies
to. There are about ten different Conditions that may apply. A
Contract is invalid if any of its Conditions are not met.
For example, a DurationCondition may specify that a Contract is only
valid within some window, while a CreditCheckCondition may specify
that a Contract is only valid if all of the signatories have passed a
credit check. There may be multiple conditions of a given kind on a
Contract. Conditions are permitted to contain other conditions (for
example, you may have an OrCondition which is true if at least one of
its subordinate Conditions is true).
The current tentative implementation uses STI, but I'm not sure this
is the right approach. There are also some issues with getting
accepts_nested_attributes_for to instantiate the correct derived
Condition type (DurationCondition, etc.) instead of always #new-ing up
Given that I'm constrained to a single Postgres datastore, what's the
best way to model my Conditions and store this data?