[Dbix-class] Pointless update on a date field
Matt S Trout
dbix-class at trout.me.uk
Wed Sep 12 17:37:55 GMT 2007
On Fri, Sep 07, 2007 at 01:51:32PM +0100, Richard Jones wrote:
> In my Catalyst app, a method is looking for a partial match on an
> existing record, then updating the record with missing data, ie
>
> my $user = $c->model('Schema::User');
>
> if ( my $partial_match = $user->find( $search_for_missing{gender} ) ) {
> # record matched on last_name, first_name, dob, etc, but ! gender
> $user->update( $form_data ); # should just update gender field
> }
>
> All appears to be working fine, but I notice from the debugging SQL that
> the date field (dob) is always updated, even though the submitted value
> is identical to the stored value of the retrieved record, ie:
>
> UPDATE users SET dob = ?, gender = ? WHERE ( id = ? )
>
> I assume this is because I am using InflateColumn::DateTime on the date
> fields. If I dump $user->last_name I get a scalar, but $user->dob gives
> me a complex data structure (the DateTime object?). But I'm not sure why
> it is trying to update the date field. Presumably it's harmless, as the
> update would silently fail anyway?
My suspicion would be that your DB isn't sending back the same datetime
string as is being saved, so the update always -thinks- the data's changed
even though the column values are equivalent.
If so, the DateTime::Format::NameOfYourDb module probably needs patching.
Fancy trying warn $obj->get_column('dob') before+after to see if I'm right?
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/
More information about the DBIx-Class
mailing list