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