[jifty-devel] Validating distinct fields

Sean E. Millichamp sean at enertronllc.com
Sun Jun 4 22:19:45 EDT 2006

On Sun, 2006-06-04 at 20:53 -0400, Edward Funnekotter wrote:
> I find for a number of models that I am using in my current project, I
> am creating actions for adding records so that I can validate that
> certain fields are not duplicated in the database rather than just
> using the Create<Name>.pm automatic action.  I think that I could do
> this my having a validation function specified in the record
> definition within my model file, but is there a reason that we don't
> just use the 'is distinct' attribute to get the Action.pm default
> validator to do the checking always?

Hi Edward,

I was actually just starting to look at what it would take to implement
'is distinct' at the Jifty::DBI layer in the last day or so.

After looking your patch over my biggest concern would be performance.
In an environment performing AJAX validations that function gets called
every time the focus moves away from any form field.  That could result
in a lot of DB queries.  I believe that the caching functionality should
handle any positive hits but on a quick skim I don't see any negative
hit caching functionality in either Jifty::DBI::Record::Cachable or
Memcached.  That would mean that for the expected case (a non-existent
value was entered into the field) it would result in a DB query for each
field marked with 'is distinct' each time focus leaves any AJAX
validated field.  In a small application I don't suspect that would be
too noticeable, but with a large dataset or large number of users that
might become a noticeable lag.

In my opinion, that particular check probably belongs in Jifty::DBI.
The notes in the docs say it is waiting for support from DBIx::DBSchema
- presumably to generate the needed SQL?  I was pondering committing a
patch exactly like yours, but at the Jifty::DBI layer.  You wouldn't
have automatic AJAX checking, but I decided that I could live with
waiting for the user to click "Submit" and performing all of the 'is
distinct' checks one time each.

As far as creating Create<name> actions just to put in the validator, I
believe you could probably do that check using the validator hook in
your Jifty::Model.  Then Jifty::Action::Record will automatically use
that validator, saving you from having to create the Create<name>


 Sean E. Millichamp, Enertron LLC, 586-757-1200 x102

More information about the jifty-devel mailing list