Merge 'trunk' into 'DBIx-Class-current'
David Kamholz [Wed, 22 Nov 2006 22:10:30 +0000 (22:10 +0000)]
r18925@haferschleim (orig r2919):  ningu | 2006-11-21 22:44:26 -0800
- slight optimization to ident_condition in PK.pm
- get ident_cond in update() before applying arguments, so a column's pk can be updated
r18926@haferschleim (orig r2920):  ningu | 2006-11-21 22:54:10 -0800
revert update() change
r18953@haferschleim (orig r2922):  ningu | 2006-11-22 12:12:43 -0800
re-commit minimal pk-mutation in update(), with test
r18956@haferschleim (orig r2924):  ningu | 2006-11-22 14:09:07 -0800
add shallow copy of $attrs in ResultSet->new

1  2 
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Row.pm

@@@ -12,6 -12,7 +12,6 @@@ use Storable
  use DBIx::Class::ResultSetColumn;
  use base qw/DBIx::Class/;
  
 -__PACKAGE__->load_components(qw/AccessorGroup/);
  __PACKAGE__->mk_group_accessors('simple' => qw/result_source result_class/);
  
  =head1 NAME
@@@ -85,6 -86,7 +85,7 @@@ sub new 
  
    my ($source, $attrs) = @_;
    #weaken $source;
+   $attrs = { %{$attrs||{}} };
  
    if ($attrs->{page}) {
      $attrs->{rows} ||= 10;
@@@ -1766,8 -1768,8 +1767,8 @@@ Which column(s) to order the results by
  through directly to SQL, so you can give e.g. C<year DESC> for a
  descending order on the column `year'.
  
 -Please note that if you have quoting enabled (see
 -L<DBIx::Class::Storage/quote_char>) you will need to do C<\'year DESC' > to
 +Please note that if you have C<quote_char> enabled (see
 +L<DBIx::Class::Storage::DBI/connect_info>) you will need to do C<\'year DESC' > to
  specify an order. (The scalar ref causes it to be passed as raw sql to the DB,
  so you will need to manually quote things as appropriate.)
  
diff --combined lib/DBIx/Class/Row.pm
@@@ -6,6 -6,8 +6,6 @@@ use warnings
  use base qw/DBIx::Class/;
  use Carp::Clan qw/^DBIx::Class/;
  
 -__PACKAGE__->load_components(qw/AccessorGroup/);
 -
  __PACKAGE__->mk_group_accessors('simple' => 'result_source');
  
  =head1 NAME
@@@ -108,12 -110,12 +108,12 @@@ required
  sub update {
    my ($self, $upd) = @_;
    $self->throw_exception( "Not in database" ) unless $self->in_storage;
    my $ident_cond = $self->ident_condition;
    $self->throw_exception("Cannot safely update a row in a PK-less table")
      if ! keys %$ident_cond;
+   $self->set_columns($upd) if $upd;
+   my %to_update = $self->get_dirty_columns;
+   return $self unless keys %to_update;
    my $rows = $self->result_source->storage->update(
                 $self->result_source->from, \%to_update, $ident_cond);
    if ($rows == 0) {