From: Matt S Trout Date: Sun, 8 Jan 2006 04:18:46 +0000 (+0000) Subject: Moved insert/update/delete to use ->result_source X-Git-Tag: v0.05005~118^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88cb6a1dc3df380393f6497a49a84524d78cc1be;p=dbsrgits%2FDBIx-Class.git Moved insert/update/delete to use ->result_source --- diff --git a/lib/DBIx/Class/DB.pm b/lib/DBIx/Class/DB.pm index cc9fecd..c0152c6 100644 --- a/lib/DBIx/Class/DB.pm +++ b/lib/DBIx/Class/DB.pm @@ -20,6 +20,14 @@ sub resultset_instance { return $table->resultset; } +sub result_source { + my $class = shift; + my $table = $class->table_instance->new($class->table_instance); + $table->storage($class->storage_instance); + $table->result_class($class); + return $table; +} + =head1 NAME DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index fc4a072..32bc631 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -53,7 +53,8 @@ sub insert { my ($self) = @_; return $self if $self->in_storage; #use Data::Dumper; warn Dumper($self); - $self->storage->insert($self->_table_name, { $self->get_columns }); + $self->result_source->storage->insert( + $self->_table_name, { $self->get_columns }); $self->in_storage(1); $self->{_dirty_columns} = {}; return $self; @@ -88,8 +89,8 @@ sub update { $self->throw( "Not in database" ) unless $self->in_storage; my %to_update = $self->get_dirty_columns; return -1 unless keys %to_update; - my $rows = $self->storage->update($self->result_source->from, \%to_update, - $self->ident_condition); + my $rows = $self->result_source->storage->update( + $self->result_source->from, \%to_update, $self->ident_condition); if ($rows == 0) { $self->throw( "Can't update ${self}: row not found" ); } elsif ($rows > 1) { @@ -114,7 +115,8 @@ sub delete { if (ref $self) { $self->throw( "Not in database" ) unless $self->in_storage; #warn $self->_ident_cond.' '.join(', ', $self->_ident_values); - $self->storage->delete($self->result_source->from, $self->ident_condition); + $self->result_source->storage->delete( + $self->result_source->from, $self->ident_condition); $self->in_storage(undef); #$self->store_column($_ => undef) for $self->primary_columns; # Should probably also arrange to trash PK if auto diff --git a/lib/DBIx/Class/TableInstance.pm b/lib/DBIx/Class/TableInstance.pm index 51966ee..ab81855 100644 --- a/lib/DBIx/Class/TableInstance.pm +++ b/lib/DBIx/Class/TableInstance.pm @@ -111,10 +111,6 @@ sub columns { return shift->table_instance->columns(@_); } -sub result_source { - return shift->table_instance(@_); -} - sub set_primary_key { shift->table_instance->set_primary_key(@_); } sub primary_columns { shift->table_instance->primary_columns(@_); }