MikeMacDowell's avatar

Polymorphic Controller Structure

I've got a set of relationships setup that define Operations and Tests, each Operation has one Test, but the Test can be of many different types, so Operation has a morphTo to Tests. This all works fine, but I want to know what the best way to approach updating the models is.

An Operation has various things defined on it like current humidity and temperature, operation number, operator etc... and the Test Models themselves have parameters which need to be entered.

What I'm trying to avoid is having to do:

  • Create Operation
  • Create Test + attach
  • Update Operation
  • Update Test attached to Operation

And instead what I'd like to do is:

  1. Create Operation and Test (this bit is working)
  2. Update Operation and Test

It's part 2 that is causing me the headache. I've got the view structure set up so the the Operations controller returns an edit view, which then includes the required Test edit view depending upon the test_type on the Operation model. All of this data is returned in a Request back to the Operations Controller, which then can do Validation and update the models - but some of the Test models need file uploads and some of them have more or less other Models attached to them.

So how do I deal with this in a nice MVC way? I could new up a Controller instance based upon test_type inside the update method of the Operations controller?

0 likes
0 replies

Please or to participate in this conversation.