[html-formfu] Re: How to write yml to confirm whether a record is
jonas.alves at gmail.com
Mon Jun 4 16:24:55 GMT 2007
On 04/06/07, Carl Franks <fireartist at gmail.com> wrote:
> On 04/06/07, Jonas Alves <jonas.alves at gmail.com> wrote:
> > On 04/06/07, Carl Franks <fireartist at gmail.com> wrote:
> > >
> > > It was originally posted to the html-widget list by Jonas Alves.
> > > I didn't add it to svn, but didn't get round to replying to explain
> > > why - my bad!
> > >
> > > Unless both the form processing and any subsequent use of the form
> > > input, are wrapped within a DB transaction - then the uniqueness check
> > > is rather useless.
> > Hi Carl,
> > Can you please explain why is it useless? I'm using this approach in production
> > and I'm satisfied with it.
> Ok, 'useless' was a rather emotive word, but I would say it's not a
> good way to do it.
> The word 'transaction' should have been enough of a clue as to what's
> wrong with it.
> If your database of choice doesn't support transactions, then you'll
> need to use a unique index on the appropriate column, and just check
> for errors when you attempt the insert.
I'm using transactions, and I'm also forcing the uniqueness with
constraints at the database level.
But I like to make the check before calling the insert method. I know
that probably is redundant, and that i could check the exception
thrown to see if it's a duplicate key error. But I prefer to check
everything before trying to insert. When i reach the model everything
should be ok. If I got an exception there then something is very wrong
and the application should die.
More information about the HTML-FormFu