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?

  • 1
    The answer to this question is going to be highly dependent on what kind of UI technologies you use. – Robert Harvey Jul 30 '15 at 4:18
  • @RobertHarvey I don't follow – Nathan Jul 30 '15 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.