Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 55004
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: cpan [...] punch.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: update to FAQ.pod
This patch came out of an irc discussion. mst said that "best practice is to call accessors, then call -> update with no argument. I wanted to add a documentation patch to reflect this. mst: change the declaration of the column to include mst: accessor => '_colname', mst: then mst: sub colname { my $self = shift; if (@_) { return $self->_colname($_[0] eq '' ? undef : $_[0]); } return $self->_colname } th1: http://paste.scsys.co.uk/39853 th1: setting it directly works now, but through update({ ... }) gives a "non-numeric" error mst: th1: ->update bypasses things mst: th1: best practice is to call accessors then call ->update with no arguments
Subject: update.faq.patch
diff -Naur DBIx-Class-0.08120.orig/lib/DBIx/Class/Manual/FAQ.pod DBIx-Class-0.08120/lib/DBIx/Class/Manual/FAQ.pod --- DBIx-Class-0.08120.orig/lib/DBIx/Class/Manual/FAQ.pod 2010-02-13 06:08:51.000000000 -0800 +++ DBIx-Class-0.08120/lib/DBIx/Class/Manual/FAQ.pod 2010-02-25 18:51:38.000000000 -0800 @@ -387,7 +387,8 @@ To stop the column name from being quoted, you'll need to supply a scalar reference: - ->update({ somecolumn => \'othercolumn' }) + ->somecolumn( \'othercolumn' ); + ->update->discard_changes; But note that when using a scalar reference the column in the database will be updated but when you read the value from the object with e.g. @@ -431,6 +432,21 @@ and more on some data within the inflated column, then it may be time to factor that data out. +=item .. the difference between accessors and update({})? + +->update() bypasses things. When you want to set values, best practices says +you should set the values individually through accessors instead of through update. + +so instead of this: + + ->update({ somecolumn => 'myvalue' }); + +do this: + + ->somecolumn( 'myvalue' ); + ->update; + + =back =head2 Custom methods in Result classes
On Thu Feb 25 22:00:33 2010, cpan@punch.net wrote: Show quoted text
> This patch came out of an irc discussion. mst said that "best practice > is to call accessors, then call -> update with no argument. > > I wanted to add a documentation patch to reflect this. > > mst: change the declaration of the column to include > mst: accessor => '_colname', > mst: then > mst: sub colname { my $self = shift; if (@_) { return > $self->_colname($_[0] eq '' ? undef : $_[0]); } return $self->_colname } > th1: http://paste.scsys.co.uk/39853 > th1: setting it directly works now, but through update({ ... }) gives a > "non-numeric" error > mst: th1: ->update bypasses things > mst: th1: best practice is to call accessors then call ->update with no > arguments
The POD is incorrect as-written. The only thing update() bypasses is calling accessors (which is arguably both a bad and a good thing). So if you override a column accessor with the _<raw_name> hack - then yes, update will never bother calling it. However if you do your overrides in set_column - then update will call them just fine. Thus the POD patch needs to be reworded from being so alarmist to highlight the caveat in which you got trapped. TIMTOWTDI :)
Avoiding update with arguments is not practical based on the current 0.08 design (even core extensions use update or equivalents internally). Rejecting docpatch as it would paint an incorrect picture of current state of affairs.