Moved insert/update/delete to use ->result_source
Matt S Trout [Sun, 8 Jan 2006 04:18:46 +0000 (04:18 +0000)]
lib/DBIx/Class/DB.pm
lib/DBIx/Class/Row.pm
lib/DBIx/Class/TableInstance.pm

index cc9fecd..c0152c6 100644 (file)
@@ -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
index fc4a072..32bc631 100644 (file)
@@ -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
index 51966ee..ab81855 100644 (file)
@@ -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(@_); }