I'm using the form object pattern to handle data normalization and validation in my app.
It's working well for simple cases, but some of my form objects are composites (or roll-ups) of multiple other form objects, in order to build out the proper associations, and validating them has become a nightmare.
For example, I have a Product which can have many Variant(s). Variant is just a subclass of Product.
A Product or a Variant can have many Feature(s).
I have a FeatureForm object that can build, validate, and save a feature. This works nicely.
I also have a VariantForm object that has many FeatureForm objects associated with it, so it builds, validates, and saves everything recursively through each nested association. This is where problems emerge.
Feature requires a product_id (which is a Product or Variant id). So when my form objects recursively validate all of their associations, the Variant is not persisted, and so does not have an id. This makes the Feature invalid, therefor making the entire composite form object invalid.
Can anyone share experiences and ideas that could help me understand how to better design a solution for this?