It seems like the question, "How do I refresh a row?" comes up fairly
often on irc and here on the list.  The answer is always
$row->discard_changes.  Refreshing is the same function from a different
perspective.  Rather than throwing my changes away (I haven't made any,
after all), I want to "refresh" my row from storage.

I discussed it briefly with mst on irc.  He dislikes the name "refresh"
and suggests, perhaps, refresh_from_storage.

A doc patch would be sufficient for users to discover discard_changes
when they're looking for refresh, but a alias that expresses the
alternate motivation might make application code more readable.

Thoughts?

        -Marc



Here's the rough draft patch:

Index: lib/DBIx/Class/PK.pm
===================================================================
--- lib/DBIx/Class/PK.pm        (revision 3310)
+++ lib/DBIx/Class/PK.pm        (working copy)
@@ -25,10 +25,11 @@
   return (map { $self->{_column_data}{$_} } $self->primary_columns);
 }
 
-=head2 discard_changes
+=head2 discard_changes, refresh_from_storage
 
 Re-selects the row from the database, losing any changes that had
-been made.
+been made.  C<refresh_from_storage> is an alias for C<discard_changes>;
+they do the same thing, but with different motivations.
 
 =cut
 
@@ -47,6 +48,10 @@
   return $self;
 }
 
+sub refresh_from_storage {
+    shift->discard_changes(@_);
+}
+
 =head2 id
 
 Returns the primary key(s) for a row. Can't be called as



_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to