X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRow.pm;h=ae72e6fd5d69a86370007b45119725800f147de5;hb=bb3dbebc510ea41f116313bbe8c9a0453707e3e5;hp=e03ab16ca551bdd5252edbf5fb436268d45ac7f9;hpb=b8810cc5d0a8888a6a2ec908cdd1c8e9a1522f97;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index e03ab16..ae72e6f 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -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 @@ -41,6 +39,9 @@ sub new { if ($attrs) { $new->throw_exception("attrs must be a hashref") unless ref($attrs) eq 'HASH'; + if (my $source = delete $attrs->{-result_source}) { + $new->result_source($source); + } foreach my $k (keys %$attrs) { $new->throw_exception("No such column $k on $class") unless $class->has_column($k); @@ -99,19 +100,20 @@ sub in_storage { $obj->update; Must be run on an object that is already in the database; issues an SQL -UPDATE query to commit any changes to the object to the db if required. +UPDATE query to commit any changes to the object to the database if +required. =cut sub update { my ($self, $upd) = @_; $self->throw_exception( "Not in database" ) unless $self->in_storage; - $self->set_columns($upd) if $upd; - my %to_update = $self->get_dirty_columns; - return $self unless keys %to_update; 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) { @@ -476,4 +478,3 @@ Matt S. Trout You may distribute this code under the same terms as Perl itself. =cut -