I'm using ZF2 and mysql, but the question is platform-independent. I have a data transfer object Organization
that gets hydrated from an html form. OrganizationMapper
has a save
method that (1) gets Organization
as an argument and (2) fills a couple of database tables one after another.
Suppose the 1st table gets filled ok, but the 2nd doesn't because one of the properties of Organization
isn't set (not null constraint on a column). The user gets an error, but the 1st table is already filled. If he attempts to submit the form again, but this time with all html fields filled, all the tables get filled ok, but the 1st has a previous unused row.
How could I avoid this situation?
I thought of checking for empty
values with if
's in the mapper's save
method, but it doesn't seem elegant. I know about the InputFilter
validations in ZF2, but these check the user input in the form, they don't check things when the php code communicates with the database.
Any help?