Patch from abraxxa to make set_primary_key barf if called with non-existant columns
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Table.pm
index 451b0bd..34e926e 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use DBIx::Class::ResultSet;
 use Data::Page;
 
-use base qw/Class::Data::Inheritable/;
+use base qw/DBIx::Class/;
 
 __PACKAGE__->mk_classdata('_columns' => {});
 
@@ -16,8 +16,6 @@ __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything
 
 __PACKAGE__->mk_classdata('_resultset_class' => 'DBIx::Class::ResultSet');
 
-__PACKAGE__->mk_classdata('_page_object');
-
 sub iterator_class { shift->_resultset_class(@_) }
 
 =head1 NAME 
@@ -102,9 +100,19 @@ sub count {
 
 =item search 
 
-  my @obj    = $class->search({ foo => 3 });
+  my @obj    = $class->search({ foo => 3 }); # "... WHERE foo = 3"
   my $cursor = $class->search({ foo => 3 });
 
+To retrieve all rows, simply call C<search()> with no condition parameter,
+
+  my @all = $class->search(); # equivalent to search({})
+
+If you need to pass in additional attributes (see
+L<DBIx::Class::ResultSet/Attributes> for details) an empty hash indicates
+no condition,
+
+  my @all = $class->search({}, { cols => [qw/foo bar/] }); # "SELECT foo, bar FROM $class_table"
+
 =cut
 
 sub search {
@@ -116,25 +124,8 @@ sub search {
   }
   $attrs->{where} = (@_ == 1 || ref $_[0] eq "HASH" ? shift: {@_});
   
-  # for pagination, we create the resultset with no limit and slice it later
-  my $page = {};
-  if ( $attrs->{page} ) {
-    map { $page->{$_} = $attrs->{$_} } qw/rows page/;
-    delete $attrs->{$_} for qw/rows offset page/;
-  }
-
   my $rs = $class->resultset($attrs);
   
-  if ( $page->{page} ) {
-    my $pager = Data::Page->new( 
-      $rs->count, 
-      $page->{rows} || 10, 
-      $page->{page} || 1 );
-    $class->_page_object( $pager );
-    return $rs->slice( $pager->skipped,
-      $pager->skipped + $pager->entries_per_page - 1 );
-  }
-  
   return (wantarray ? $rs->all : $rs);
 }
 
@@ -193,18 +184,40 @@ sub find_or_create {
   return defined($exists) ? $exists : $class->create($hash);
 }
 
-sub columns { return keys %{shift->_columns}; }
-
-=item page
+=item has_column                                                                
+                                                                                
+  if ($obj->has_column($col)) { ... }                                           
+                                                                                
+Returns 1 if the object has a column of this name, 0 otherwise                  
+                                                                                
+=cut                                                                            
+
+sub has_column {
+  my ($self, $column) = @_;
+  return exists $self->_columns->{$column};
+}
 
-  $pager = $class->page;
-  
-Returns a Data::Page object for the most recent search that was performed
-using the page parameter.
+=item column_info                                                               
+                                                                                
+  my $info = $obj->column_info($col);                                           
+                                                                                
+Returns the column metadata hashref for the column                              
+                                                                                
+=cut                                                                            
+
+sub column_info {
+  my ($self, $column) = @_;
+  die "No such column $column" unless exists $self->_columns->{$column};
+  return $self->_columns->{$column};
+}
 
-=cut
+=item columns                                                                   
+                                                                                
+  my @column_names = $obj->columns;                                             
+                                                                                
+=cut                                                                            
 
-sub page { shift->_page_object }
+sub columns { return keys %{shift->_columns}; }
 
 1;