views:

23

answers:

0

How should I validate data going into multiple tables that all depend on each other?

I have a debate site, where users can start a debate and with their debate submit "survey options" so people can choose an option when they reply to the debate.

The validation process goes like this, the debate model validates that the columns specific to the debate table are valid (topic, and body). The options model validates that the options supplied with the debate are valid (text). The category model validates that the category that the user supplied for that debate actually exists.

What i usually do is make sure everything exists before i add anything to the database. So when adding a debate, I would make sure the category exists. When adding a survey option to a debate, I want to make sure the debate exists. The problem arises when creating a new debate with survey options at the same time. By making it so that the debate exists prior to adding a new option, I end up in a Catch 22. The debate wont add (and therefore wont exist) unless EVERYHING validates, and the survey options wont validate unless the debate exists, because it needs a debate id to bind to.

So, should I remove this logic from my survey options? what should I do

Thanks