Merge 'trunk' into 'sqla_1.50_compat'
Norbert Buchmuller [Sun, 18 Jan 2009 19:40:39 +0000 (19:40 +0000)]
r5390@vger:  mendel | 2009-01-12 11:30:01 +0100
 r5351@vger (orig r5266):  norbi | 2008-12-21 01:39:44 +0100
  r5350@vger:  mendel | 2008-12-21 01:39:37 +0100
   * Added myself to the contributors list.

 r5354@vger (orig r5269):  ribasushi | 2008-12-21 12:24:39 +0100
 delete() POD patch from Michael Hendricks (slightly reworded)
 r5365@vger (orig r5278):  nothingmuch | 2008-12-22 17:43:50 +0100
 map blob to PG_BYTEA on DBD::Pg
 r5366@vger (orig r5279):  matthewt | 2008-12-24 18:26:35 +0100
 make clear that search_like is only really there for Class::DBI users
 r5367@vger (orig r5280):  castaway | 2008-12-29 22:51:54 +0100
 Added standard arguments/return value to all docced methods.
 Upadted some method docs.

 r5368@vger (orig r5281):  castaway | 2008-12-29 23:17:37 +0100
 Re-ordered method docs to be in a more user-needs-it order.
 Fixed some obj/table mentions in docs to be consistently $source.

 r5369@vger (orig r5282):  castaway | 2008-12-30 11:58:19 +0100
 Add definitions of relationship and relationship bridge, link to them from the rel docs

 r5377@vger (orig r5290):  rjbs | 2009-01-08 21:49:29 +0100
  failing test for callback on_connect_do getting storage obejct
 r5378@vger (orig r5291):  rjbs | 2009-01-08 21:50:57 +0100
 fix the just-added test; pass the Storage object to pure-code on_connect callbacks
 r5379@vger (orig r5292):  rjbs | 2009-01-08 21:51:39 +0100
 credit where credit is due; namely: ME!
 r5381@vger (orig r5294):  wreis | 2009-01-08 23:45:35 +0100
 failing test for load_namespace
 r5382@vger (orig r5295):  wreis | 2009-01-08 23:57:47 +0100
 ->result_source_instance->source_name should return undef for any class
 r5383@vger (orig r5296):  wreis | 2009-01-09 00:11:50 +0100
 reverting changes for versioning tests
 r5384@vger (orig r5297):  rjbs | 2009-01-09 02:55:53 +0100
 by setting conn_?id first, we prevent $storage->dbh from recursing through on_connect_do actions
 r5385@vger (orig r5298):  matthewt | 2009-01-09 04:28:44 +0100
 fixup source registration bugs where schema-specific things were being set on class' result_source_instance objects
 r5386@vger (orig r5299):  wreis | 2009-01-09 13:14:49 +0100
 not necessary
 r5389@vger (orig r5300):  norbi | 2009-01-12 11:18:47 +0100
  r5388@vger:  mendel | 2009-01-12 11:18:22 +0100
   * Implemented $rs->current_source_alias.

14 files changed:
lib/DBIx/Class.pm
lib/DBIx/Class/DB.pm
lib/DBIx/Class/Manual/Glossary.pod
lib/DBIx/Class/Relationship.pm
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy/Table.pm
lib/DBIx/Class/Row.pm
lib/DBIx/Class/Schema.pm
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/Pg.pm
t/39load_namespaces_1.t
t/76select.t
t/92storage_on_connect_do.t

index 60a80fd..0d10c8c 100644 (file)
@@ -287,6 +287,8 @@ rdj: Ryan D Johnson <ryan@innerfence.com>
 
 ribasushi: Peter Rabbitson <rabbit@rabbit.us>
 
+rjbs: Ricardo Signes <rjbs@cpan.org>
+
 sc_: Just Another Perl Hacker
 
 scotty: Scotty Allen <scotty@scottyallen.com>
@@ -311,6 +313,8 @@ willert: Sebastian Willert <willert@cpan.org>
 
 zamolxes: Bogdan Lucaciu <bogdan@wiz.ro>
 
+norbi: Norbert Buchmuller <norbi@nix.hu>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
index eadb5ad..1f1ffd8 100644 (file)
@@ -152,27 +152,47 @@ Returns an instance of the result source for this class
 
 __PACKAGE__->mk_classdata('_result_source_instance' => []);
 
+# Yep. this is horrific. Basically what's happening here is that
+# (with good reason) DBIx::Class::Schema copies the result source for
+# registration. Because we have a retarded setup order forced on us we need
+# to actually make our ->result_source_instance -be- the source used, and we
+# need to get the source name and schema into ourselves. So this makes it
+# happen.
+
+sub _maybe_attach_source_to_schema {
+  my ($class, $source) = @_;
+  if (my $meth = $class->can('schema_instance')) {
+    my $schema = $class->$meth;
+    $schema->register_class($class, $class);
+    my $new_source = $schema->source($class);
+    %$source = %$new_source;
+    $schema->source_registrations->{$class} = $source;
+  }
+}
+
 sub result_source_instance {
   my $class = shift;
   $class = ref $class || $class;
   
-  return $class->_result_source_instance([$_[0], $class]) if @_;
+  if (@_) {
+    my $source = $_[0];
+    $class->_result_source_instance([$source, $class]);
+    $class->_maybe_attach_source_to_schema($source);
+    return $source;
+  }
 
   my($source, $result_class) = @{$class->_result_source_instance};
   return unless Scalar::Util::blessed($source);
 
   if ($result_class ne $class) {  # new class
     # Give this new class it's own source and register it.
-
     $source = $source->new({ 
         %$source, 
         source_name  => $class,
         result_class => $class
     } );
     $class->_result_source_instance([$source, $class]);
-    if (my $coderef = $class->can('schema_instance')) {
-        $coderef->($class)->register_class($class, $class);
-    }
+    $class->_maybe_attach_source_to_schema($source);
   }
   return $source;
 }
index 818e88a..a70ffa1 100644 (file)
@@ -36,6 +36,18 @@ Object-relational mapping, or Object-relationship modelling. Either
 way it's a method of mapping the contents of database tables (rows),
 to objects in programming-language-space. DBIx::Class is an ORM.
 
+=head2 Relationship
+
+In DBIx::Class a relationship defines the connection between exactly
+two tables. The relationship condition lists the columns in each table
+that contain the same values. It is used to output an SQL JOIN
+condition between the tables.
+
+=head2 Relationship bridge
+
+A relationship bridge, such as C<many_to_many> defines an accessor to
+retrieve row contents across multiple relationships.
+
 =head2 ResultSet
 
 This is an object representing a set of data. It can either be an
index 3479ac2..67e4f68 100644 (file)
@@ -39,6 +39,9 @@ See L<DBIx::Class::Manual::Cookbook> for more.
 
 =head1 DESCRIPTION
 
+The word I<Relationship> has a specific meaning in DBIx::Class, see
+the definition in the L<Glossary|DBIx::Class::Manual::Glossary/Relationship>.
+
 This class provides methods to set up relationships between the tables
 in your database model. Relationships are the most useful and powerful
 technique that L<DBIx::Class> provides. To create efficient database queries,
@@ -102,20 +105,20 @@ L<DBIx::Class::Relationship::Base>.
 
 All helper methods are called similar to the following template:
 
-  __PACKAGE__->$method_name('relname', 'Foreign::Class', $cond, $attrs);
+  __PACKAGE__->$method_name('relname', 'Foreign::Class', \%cond | \@cond, \%attrs);
   
 Both C<$cond> and C<$attrs> are optional. Pass C<undef> for C<$cond> if
-you want to use the default value for it, but still want to set C<$attrs>.
+you want to use the default value for it, but still want to set C<\%attrs>.
 
 See L<DBIx::Class::Relationship::Base> for documentation on the
-attrubutes that are allowed in the C<$attrs> argument.
+attrubutes that are allowed in the C<\%attrs> argument.
 
 
 =head2 belongs_to
 
 =over 4
 
-=item Arguments: $accessor_name, $related_class, $our_fk_column|\%cond|\@cond?, \%attr?
+=item Arguments: $accessor_name, $related_class, $our_fk_column|\%cond|\@cond?, \%attrs?
 
 =back
 
@@ -225,7 +228,7 @@ which can be assigned to relationships as well.
 
 =over 4
 
-=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr?
+=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs?
 
 =back
 
@@ -358,7 +361,7 @@ which can be assigned to relationships as well.
 
 =over 4
 
-=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr?
+=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs?
 
 =back
 
@@ -442,7 +445,7 @@ which can be assigned to relationships as well.
 
 =over 4
 
-=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr?
+=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs?
 
 =back
 
@@ -529,10 +532,14 @@ which can be assigned to relationships as well.
 
 =over 4
 
-=item Arguments: $accessor_name, $link_rel_name, $foreign_rel_name, \%attr?
+=item Arguments: $accessor_name, $link_rel_name, $foreign_rel_name, \%attrs?
 
 =back
 
+C<many_to_many> is a I<Relationship bridge> which has a specific
+meaning in DBIx::Class, see the definition in the
+L<Glossary|DBIx::Class::Manual::Glossary/Relationship bridge>.
+
 C<many_to_many> is not strictly a relationship in its own right. Instead, it is
 a bridge between two resultsets which provide the same kind of convenience
 accessors as true relationships provide. Although the accessor will return a 
index e637aee..8f9d601 100644 (file)
@@ -737,8 +737,8 @@ sub get_column {
   $cd_rs = $rs->search_like({ title => '%blue%'});
 
 Performs a search, but uses C<LIKE> instead of C<=> as the condition. Note
-that this is simply a convenience method. You most likely want to use
-L</search> with specific operators.
+that this is simply a convenience method retained for ex Class::DBI users.
+You most likely want to use L</search> with specific operators.
 
 For more information, see L<DBIx::Class::Manual::Cookbook>.
 
@@ -2094,6 +2094,50 @@ sub related_resultset {
   };
 }
 
+=head2 current_source_alias
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $source_alias
+
+=back
+
+Returns the current alias of the result source that corrensponds to the result
+set (this alias will eventually be used as the SQL table alias in the SQL
+query). Usually it is C<me>.
+
+Currently the source alias that refers to the result set returned by a
+L</search>/L</find> family method depends on how you got to the resultset: it's
+C<me> by default, but eg. L</search_related> aliases it to the related result
+source name (and keeps C<me> referring to the original result set). The long
+term goal is to make L<DBIx::Class> always alias the current resultset as C<me>
+(and make this method unnecessary).
+
+Thus it's currently necessary to use this method in predefined queries (see
+L<DBIx::Class::Manual::Cookbook/Predefined searches>) when referring to the
+source alias of the current result set:
+
+  # in a result set class
+  sub modified_by {
+    my ($self, $user) = @_;
+
+    my $me = $self->current_source_alias;
+
+    return $self->search(
+      "$me.modified" => $user->id,
+    );
+  }
+
+=cut
+
+sub current_source_alias {
+  my ($self) = @_;
+
+  return ($self->{attrs} || {})->{alias} || 'me';
+}
+
 sub _resolve_from {
   my ($self, $extra_join) = @_;
   my $source = $self->result_source;
index 83ad7cc..3946d7c 100644 (file)
@@ -33,14 +33,6 @@ retrieved, most usually a table (see L<DBIx::Class::ResultSource::Table>)
 
 =pod
 
-=head2 new
-
-  $class->new();
-
-  $class->new({attribute_name => value});
-
-Creates a new ResultSource object.  Not normally called directly by end users.
-
 =cut
 
 sub new {
@@ -60,22 +52,19 @@ sub new {
 
 =pod
 
-=head2 source_info
+=head2 add_columns
 
-Stores a hashref of per-source metadata.  No specific key names
-have yet been standardized, the examples below are purely hypothetical
-and don't actually accomplish anything on their own:
+=over
 
-  __PACKAGE__->source_info({
-    "_tablespace" => 'fast_disk_array_3',
-    "_engine" => 'InnoDB',
-  });
+=item Arguments: @columns
 
-=head2 add_columns
+=item Return value: The ResultSource object
+
+=back
 
-  $table->add_columns(qw/col1 col2 col3/);
+  $source->add_columns(qw/col1 col2 col3/);
 
-  $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
+  $source->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
 
 Adds columns to the result source. If supplied key => hashref pairs, uses
 the hashref as the column_info for that column. Repeated calls of this
@@ -161,9 +150,18 @@ L<SQL::Translator::Producer::MySQL>.
 
 =head2 add_column
 
-  $table->add_column('col' => \%info?);
+=over
 
-Convenience alias to add_columns.
+=item Arguments: $colname, [ \%columninfo ]
+
+=item Return value: 1/0 (true/false)
+
+=back
+
+  $source->add_column('col' => \%info?);
+
+Add a single column and optional column info. Uses the same column
+info keys as L</add_columns>.
 
 =cut
 
@@ -188,7 +186,15 @@ sub add_column { shift->add_columns(@_); } # DO NOT CHANGE THIS TO GLOB
 
 =head2 has_column
 
-  if ($obj->has_column($col)) { ... }
+=over
+
+=item Arguments: $colname
+
+=item Return value: 1/0 (true/false)
+
+=back
+
+  if ($source->has_column($colname)) { ... }
 
 Returns true if the source has a column of this name, false otherwise.
 
@@ -201,10 +207,19 @@ sub has_column {
 
 =head2 column_info
 
-  my $info = $obj->column_info($col);
+=over
+
+=item Arguments: $colname
 
-Returns the column metadata hashref for a column. See the description
-of add_column for information on the contents of the hashref.
+=item Return value: Hashref of info
+
+=back
+
+  my $info = $source->column_info($col);
+
+Returns the column metadata hashref for a column, as originally passed
+to L</add_columns>. See the description of L</add_columns> for information
+on the contents of the hashref.
 
 =cut
 
@@ -238,19 +253,19 @@ sub column_info {
   return $self->_columns->{$column};
 }
 
-=head2 column_info_from_storage
+=head2 columns
 
-Enables the on-demand automatic loading of the above column
-metadata from storage as neccesary.  This is *deprecated*, and
-should not be used.  It will be removed before 1.0.
+=over
 
-  __PACKAGE__->column_info_from_storage(1);
+=item Arguments: None
 
-=head2 columns
+=item Return value: Ordered list of column names
+
+=back
 
-  my @column_names = $obj->columns;
+  my @column_names = $source->columns;
 
-Returns all column names in the order they were declared to add_columns.
+Returns all column names in the order they were declared to L</add_columns>.
 
 =cut
 
@@ -264,15 +279,40 @@ sub columns {
 
 =head2 remove_columns
 
-  $table->remove_columns(qw/col1 col2 col3/);
+=over
+
+=item Arguments: @colnames
+
+=item Return value: undefined
+
+=back
+
+  $source->remove_columns(qw/col1 col2 col3/);
 
-Removes columns from the result source.
+Removes the given list of columns by name, from the result source.
+
+B<Warning>: Removing a column that is also used in the sources primary
+key, or in one of the sources unique constraints, B<will> result in a
+broken result source.
 
 =head2 remove_column
 
-  $table->remove_column('col');
+=over
+
+=item Arguments: $colname
+
+=item Return value: undefined
+
+=back
+
+  $source->remove_column('col');
+
+Remove a single column by name from the result source, similar to
+L</remove_columns>.
 
-Convenience alias to remove_columns.
+B<Warning>: Removing a column that is also used in the sources primary
+key, or in one of the sources unique constraints, B<will> result in a
+broken result source.
 
 =cut
 
@@ -303,12 +343,15 @@ sub remove_column { shift->remove_columns(@_); } # DO NOT CHANGE THIS TO GLOB
 
 =item Arguments: @cols
 
+=item Return value: undefined
+
 =back
 
 Defines one or more columns as primary key for this source. Should be
-called after C<add_columns>.
+called after L</add_columns>.
 
-Additionally, defines a unique constraint named C<primary>.
+Additionally, defines a L<unique constraint|add_unique_constraint>
+named C<primary>.
 
 The primary key columns are used by L<DBIx::Class::PK::Auto> to
 retrieve automatically created values from the database.
@@ -329,7 +372,16 @@ sub set_primary_key {
 
 =head2 primary_columns
 
-Read-only accessor which returns the list of primary keys.
+=over 4
+
+=item Arguments: None
+
+=item Return value: Ordered list of primary column names
+
+=back
+
+Read-only accessor which returns the list of primary keys, supplied by
+L</set_primary_key>.
 
 =cut
 
@@ -339,6 +391,14 @@ sub primary_columns {
 
 =head2 add_unique_constraint
 
+=over 4
+
+=item Arguments: [ $name ], \@colnames
+
+=item Return value: undefined
+
+=back
+
 Declare a unique constraint on this source. Call once for each unique
 constraint.
 
@@ -357,6 +417,9 @@ C<table> is replaced with the table name.
 Unique constraints are used, for example, when you call
 L<DBIx::Class::ResultSet/find>. Only columns in the constraint are searched.
 
+Throws an error if any of the given column names do not yet exist on
+the result source.
+
 =cut
 
 sub add_unique_constraint {
@@ -378,12 +441,29 @@ sub add_unique_constraint {
 
 =head2 name_unique_constraint
 
-Return a name for a unique constraint containing the specified columns. These
-names consist of the table name and each column name, separated by underscores.
+=over 4
+
+=item Arguments: @colnames
+
+=item Return value: Constraint name
+
+=back
+
+  $source->table('mytable');
+  $source->name_unique_constraint('col1', 'col2');
+  # returns
+  'mytable_col1_col2'
+
+Return a name for a unique constraint containing the specified
+columns. The name is created by joining the table name and each column
+name, using an underscore character.
 
 For example, a constraint on a table named C<cd> containing the columns
 C<artist> and C<title> would result in a constraint name of C<cd_artist_title>.
 
+This is used by L</add_unique_constraint> if you do not specify the
+optional constraint name.
+
 =cut
 
 sub name_unique_constraint {
@@ -394,7 +474,20 @@ sub name_unique_constraint {
 
 =head2 unique_constraints
 
-Read-only accessor which returns the list of unique constraints on this source.
+=over 4
+
+=item Arguments: None
+
+=item Return value: Hash of unique constraint data
+
+=back
+
+  $source->unique_constraints();
+
+Read-only accessor which returns a hash of unique constraints on this source.
+
+The hash is keyed by constraint name, and contains an arrayref of
+column names as values.
 
 =cut
 
@@ -404,6 +497,16 @@ sub unique_constraints {
 
 =head2 unique_constraint_names
 
+=over 4
+
+=item Arguments: None
+
+=item Return value: Unique constraint names
+
+=back
+
+  $source->unique_constraint_names();
+
 Returns the list of unique constraint names defined on this source.
 
 =cut
@@ -418,6 +521,16 @@ sub unique_constraint_names {
 
 =head2 unique_constraint_columns
 
+=over 4
+
+=item Arguments: $constraintname
+
+=item Return value: List of constraint columns
+
+=back
+
+  $source->unique_constraint_columns('myconstraint');
+
 Returns the list of columns that make up the specified unique constraint.
 
 =cut
@@ -434,19 +547,144 @@ sub unique_constraint_columns {
   return @{ $unique_constraints{$constraint_name} };
 }
 
+=head2 resultset
+
+=over 4
+
+=item Arguments: None
+
+=item Return value: $resultset
+
+=back
+
+Returns a resultset for the given source. This will initially be created
+on demand by calling
+
+  $self->resultset_class->new($self, $self->resultset_attributes)
+
+but is cached from then on unless resultset_class changes.
+
+=head2 resultset_class
+
+=over 4
+
+=item Arguments: $classname
+
+=item Return value: $classname
+
+=back
+
+  package My::ResultSetClass;
+  use base 'DBIx::Class::ResultSet';
+  ...
+
+  $source->resultset_class('My::ResultSet::Class');
+
+Set the class of the resultset, this is useful if you want to create your
+own resultset methods. Create your own class derived from
+L<DBIx::Class::ResultSet>, and set it here. If called with no arguments,
+this method returns the name of the existing resultset class, if one
+exists.
+
+=head2 resultset_attributes
+
+=over 4
+
+=item Arguments: \%attrs
+
+=item Return value: \%attrs
+
+=back
+
+  $source->resultset_attributes({ order_by => [ 'id' ] });
+
+Store a collection of resultset attributes, that will be set on every
+L<DBIx::Class::ResultSet> produced from this result source. For a full
+list see L<DBIx::Class::ResultSet/ATTRIBUTES>.
+
+=cut
+
+sub resultset {
+  my $self = shift;
+  $self->throw_exception(
+    'resultset does not take any arguments. If you want another resultset, '.
+    'call it on the schema instead.'
+  ) if scalar @_;
+
+  return $self->resultset_class->new(
+    $self,
+    {
+      %{$self->{resultset_attributes}},
+      %{$self->schema->default_resultset_attributes}
+    },
+  );
+}
+
+=head2 source_name
+
+=over 4
+
+=item Arguments: $source_name
+
+=item Result value: $source_name
+
+=back
+
+Set an alternate name for the result source when it is loaded into a schema.
+This is useful if you want to refer to a result source by a name other than
+its class name.
+
+  package ArchivedBooks;
+  use base qw/DBIx::Class/;
+  __PACKAGE__->table('books_archive');
+  __PACKAGE__->source_name('Books');
+
+  # from your schema...
+  $schema->resultset('Books')->find(1);
+
 =head2 from
 
+=over 4
+
+=item Arguments: None
+
+=item Return value: FROM clause
+
+=back
+
+  my $from_clause = $source->from();
+
 Returns an expression of the source to be supplied to storage to specify
 retrieval from this source. In the case of a database, the required FROM
 clause contents.
 
 =head2 schema
 
+=over 4
+
+=item Arguments: None
+
+=item Return value: A schema object
+
+=back
+
+  my $schema = $source->schema();
+
 Returns the L<DBIx::Class::Schema> object that this result source 
-belongs too.
+belongs to.
 
 =head2 storage
 
+=over 4
+
+=item Arguments: None
+
+=item Return value: A Storage object
+
+=back
+
+  $source->storage->debug(1);
+
 Returns the storage handle for the current schema.
 
 See also: L<DBIx::Class::Storage>
@@ -457,8 +695,20 @@ sub storage { shift->schema->storage; }
 
 =head2 add_relationship
 
+=over 4
+
+=item Arguments: $relname, $related_source_name, \%cond, [ \%attrs ]
+
+=item Return value: 1/true if it succeeded
+
+=back
+
   $source->add_relationship('relname', 'related_source', $cond, $attrs);
 
+L<DBIx::Class::Relationship> describes a series of methods which
+create pre-defined useful types of relationships. Look there first
+before using this method directly.
+
 The relationship name can be arbitrary, but must be unique for each
 relationship attached to this result source. 'related_source' should
 be the name with which the related result source was registered with
@@ -470,7 +720,7 @@ the current schema. For example:
 
 The condition C<$cond> needs to be an L<SQL::Abstract>-style
 representation of the join between the tables. For example, if you're
-creating a rel from Author to Book,
+creating a relation from Author to Book,
 
   { 'foreign.author_id' => 'self.id' }
 
@@ -517,6 +767,9 @@ relationship.
 
 =back
 
+Throws an exception if the condition is improperly supplied, or cannot
+be resolved using L</resolve_join>.
+
 =cut
 
 sub add_relationship {
@@ -567,6 +820,16 @@ sub add_relationship {
 
 =head2 relationships
 
+=over 4
+
+=item Arguments: None
+
+=item Return value: List of relationship names
+
+=back
+
+  my @relnames = $source->relationships();
+
 Returns all relationship names for this source.
 
 =cut
@@ -581,10 +844,12 @@ sub relationships {
 
 =item Arguments: $relname
 
+=item Return value: Hashref of relation data,
+
 =back
 
 Returns a hash of relationship information for the specified relationship
-name.
+name. The keys/values are as specified for L</add_relationship>.
 
 =cut
 
@@ -599,6 +864,8 @@ sub relationship_info {
 
 =item Arguments: $rel
 
+=item Return value: 1/0 (true/false)
+
 =back
 
 Returns true if the source has a relationship of this name, false otherwise.
@@ -616,10 +883,21 @@ sub has_relationship {
 
 =item Arguments: $relname
 
+=item Return value: Hashref of relationship data
+
 =back
 
-Returns an array of hash references of relationship information for
-the other side of the specified relationship name.
+Looks through all the relationships on the source this relationship
+points to, looking for one whose condition is the reverse of the
+condition on this relationship.
+
+A common use of this is to find the name of the C<belongs_to> relation
+opposing a C<has_many> relation. For definition of these look in
+L<DBIx::Class::Relationship>.
+
+The returned hashref is keyed by the name of the opposing
+relationship, and contains it's data in the same manner as
+L</relationship_info>.
 
 =cut
 
@@ -676,7 +954,9 @@ sub reverse_relationship_info {
 
 =over 4
 
-=item Arguments: $keys1, $keys2
+=item Arguments: \@keys1, \@keys2
+
+=item Return value: 1/0 (true/false)
 
 =back
 
@@ -717,12 +997,36 @@ sub compare_relationship_keys {
   return $found;
 }
 
+=head2 sqlt_deploy_hook
+
+=over 4
+
+=item Arguments: $source, $sqlt_table
+
+=item Return value: undefined
+
+=back
+
+This is NOT a method of C<ResultSource>.
+
+An optional sub which you can declare in your own Result class that will get 
+passed the L<SQL::Translator::Schema::Table> object when you deploy the schema
+via L</create_ddl_dir> or L</deploy>.
+
+This is useful to make L<SQL::Translator> create non-unique indexes,
+or set table options such as C<Engine=INNOFB>.
+
+For an example of what you can do with this, see 
+L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
+
 =head2 resolve_join
 
 =over 4
 
 =item Arguments: $relation
 
+=item Return value: Join condition arrayref
+
 =back
 
 Returns the join structure required for the related result source.
@@ -774,6 +1078,8 @@ sub resolve_join {
 
 =item Arguments: $relname, $rel_data
 
+=item Return value: 1/0 (true/false)
+
 =back
 
 Determines whether a relation is dependent on an object from this source
@@ -1000,6 +1306,8 @@ sub resolve_prefetch {
 
 =item Arguments: $relname
 
+=item Return value: $source
+
 =back
 
 Returns the result source object for the given relationship.
@@ -1020,6 +1328,8 @@ sub related_source {
 
 =item Arguments: $relname
 
+=item Return value: $classname
+
 =back
 
 Returns the class name for objects in the given relationship.
@@ -1034,75 +1344,6 @@ sub related_class {
   return $self->schema->class($self->relationship_info($rel)->{source});
 }
 
-=head2 resultset
-
-Returns a resultset for the given source. This will initially be created
-on demand by calling
-
-  $self->resultset_class->new($self, $self->resultset_attributes)
-
-but is cached from then on unless resultset_class changes.
-
-=head2 resultset_class
-
-` package My::ResultSetClass;
-  use base 'DBIx::Class::ResultSet';
-  ...
-
-  $source->resultset_class('My::ResultSet::Class');
-
-Set the class of the resultset, this is useful if you want to create your
-own resultset methods. Create your own class derived from
-L<DBIx::Class::ResultSet>, and set it here. If called with no arguments,
-this method returns the name of the existing resultset class, if one
-exists.
-
-=head2 resultset_attributes
-
-  $source->resultset_attributes({ order_by => [ 'id' ] });
-
-Specify here any attributes you wish to pass to your specialised
-resultset. For a full list of these, please see
-L<DBIx::Class::ResultSet/ATTRIBUTES>.
-
-=cut
-
-sub resultset {
-  my $self = shift;
-  $self->throw_exception(
-    'resultset does not take any arguments. If you want another resultset, '.
-    'call it on the schema instead.'
-  ) if scalar @_;
-
-  return $self->resultset_class->new(
-    $self,
-    {
-      %{$self->{resultset_attributes}},
-      %{$self->schema->default_resultset_attributes}
-    },
-  );
-}
-
-=head2 source_name
-
-=over 4
-
-=item Arguments: $source_name
-
-=back
-
-Set the name of the result source when it is loaded into a schema.
-This is usefull if you want to refer to a result source by a name other than
-its class name.
-
-  package ArchivedBooks;
-  use base qw/DBIx::Class/;
-  __PACKAGE__->table('books_archive');
-  __PACKAGE__->source_name('Books');
-
-  # from your schema...
-  $schema->resultset('Books')->find(1);
-
 =head2 handle
 
 Obtain a new handle to this source. Returns an instance of a 
@@ -1132,14 +1373,42 @@ sub throw_exception {
   }
 }
 
-=head2 sqlt_deploy_hook($sqlt_table)
+=head2 source_info
 
-An optional sub which you can declare in your own Schema class that will get 
-passed the L<SQL::Translator::Schema::Table> object when you deploy the schema
-via L</create_ddl_dir> or L</deploy>.
+Stores a hashref of per-source metadata.  No specific key names
+have yet been standardized, the examples below are purely hypothetical
+and don't actually accomplish anything on their own:
 
-For an example of what you can do with this, see 
-L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
+  __PACKAGE__->source_info({
+    "_tablespace" => 'fast_disk_array_3',
+    "_engine" => 'InnoDB',
+  });
+
+=head2 new
+
+  $class->new();
+
+  $class->new({attribute_name => value});
+
+Creates a new ResultSource object.  Not normally called directly by end users.
+
+=cut
+
+=head2 column_info_from_storage
+
+=over
+
+=item Arguments: 1/0 (default: 0)
+
+=item Return value: 1/0
+
+=back
+
+Enables the on-demand automatic loading of the above column
+metadata from storage as neccesary.  This is *deprecated*, and
+should not be used.  It will be removed before 1.0.
+
+  __PACKAGE__->column_info_from_storage(1);
 
 =head1 AUTHORS
 
index a1abb1b..5cfe4f3 100644 (file)
@@ -40,11 +40,6 @@ sub _init_result_source_instance {
 
     $class->result_source_instance($table);
 
-    if ($class->can('schema_instance') && $class->schema_instance) {
-        $class =~ m/([^:]+)$/;
-        $class->schema_instance->register_class($class, $class);
-    }
-
     return $table;
 }
 
@@ -95,10 +90,6 @@ sub table {
 
   $class->result_source_instance($table);
 
-  if ($class->can('schema_instance')) {
-    $class =~ m/([^:]+)$/;
-    $class->schema_instance->register_class($class, $class);
-  }
   return $class->result_source_instance->name;
 }
 
index c1fb2b0..134e841 100644 (file)
@@ -450,6 +450,14 @@ hashref of the relationship, see L<DBIx::Class::Relationship>. Any
 database-level cascade or restrict will take precedence over a
 DBIx-Class-based cascading delete. 
 
+If you delete an object within a txn_do() (see L<DBIx::Class::Storage/txn_do>)
+and the transaction subsequently fails, the row object will remain marked as
+not being in storage. If you know for a fact that the object is still in
+storage (i.e. by inspecting the cause of the transaction's failure), you can
+use C<< $obj->in_storage(1) >> to restore consistency between the object and
+the database. This would allow a subsequent C<< $obj->delete >> to work
+as expected.
+
 See also L<DBIx::Class::ResultSet/delete>.
 
 =cut
index cf054d0..102e259 100644 (file)
@@ -211,7 +211,6 @@ sub load_namespaces {
     foreach my $result (keys %results) {
       my $result_class = $results{$result};
       $class->ensure_class_loaded($result_class);
-      $result_class->source_name($result) unless $result_class->source_name;
 
       my $rs_class = delete $resultsets{$result};
       my $rs_set = $result_class->resultset_class;
@@ -226,7 +225,9 @@ sub load_namespaces {
         $result_class->resultset_class($rs_class);
       }
 
-      push(@to_register, [ $result_class->source_name, $result_class ]);
+      my $source_name = $result_class->source_name || $result;
+
+      push(@to_register, [ $source_name, $result_class ]);
     }
   }
 
@@ -1228,7 +1229,7 @@ sub register_extra_source {
 sub _register_source {
   my ($self, $moniker, $source, $params) = @_;
 
-  %$source = %{ $source->new( { %$source, source_name => $moniker }) };
+  $source = $source->new({ %$source, source_name => $moniker });
 
   my %reg = %{$self->source_registrations};
   $reg{$moniker} = $source;
index 5eefa25..91e44e3 100644 (file)
@@ -893,11 +893,11 @@ sub _populate_dbh {
     }
   }
 
-  my $connection_do = $self->on_connect_do;
-  $self->_do_connection_actions($connection_do) if ref($connection_do);
-
   $self->_conn_pid($$);
   $self->_conn_tid(threads->tid) if $INC{'threads.pm'};
+
+  my $connection_do = $self->on_connect_do;
+  $self->_do_connection_actions($connection_do) if ref($connection_do);
 }
 
 sub _do_connection_actions {
@@ -908,7 +908,7 @@ sub _do_connection_actions {
     $self->_do_query($_) foreach @$connection_do;
   }
   elsif (ref $connection_do eq 'CODE') {
-    $connection_do->();
+    $connection_do->($self);
   }
 
   return $self;
index 937edfb..5fcaa17 100644 (file)
@@ -70,6 +70,7 @@ sub bind_attribute_by_data_type {
 
   my $bind_attributes = {
     bytea => { pg_type => DBD::Pg::PG_BYTEA },
+    blob  => { pg_type => DBD::Pg::PG_BYTEA },
   };
  
   if( defined $bind_attributes->{$data_type} ) {
index 7911d8d..84ddd83 100644 (file)
@@ -6,7 +6,7 @@ use Test::More;
 
 unshift(@INC, './t/lib');
 
-plan tests => 6;
+plan tests => 8;
 
 my $warnings;
 eval {
@@ -27,3 +27,8 @@ my $source_b = DBICNSTest->source('B');
 isa_ok($source_b, 'DBIx::Class::ResultSource::Table');
 my $rset_b   = DBICNSTest->resultset('B');
 isa_ok($rset_b, 'DBIx::Class::ResultSet');
+
+for my $moniker (qw/A B/) {
+  my $class = "DBICNSTest::Result::$moniker";
+  ok(!defined($class->result_source_instance->source_name));
+}
index 2d60873..4325a70 100644 (file)
@@ -8,7 +8,7 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 11;
+plan tests => 12;
 
 my $rs = $schema->resultset('CD')->search({},
     {
@@ -61,3 +61,5 @@ my $subsel = $cds->search ({}, {
 is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds');
 is ($subsel->next->title, $cds->next->title, 'First CD title match');
 is ($subsel->next->title, $cds->next->title, 'Second CD title match');
+
+is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');
index 62712af..6c467cd 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 10;
 
 use lib qw(t/lib);
 use base 'DBICTest';
@@ -33,11 +33,11 @@ ok $@, 'Searching for nonexistent table dies';
 
 $schema->storage->disconnect();
 
-my($connected, $disconnected);
+my($connected, $disconnected, @cb_args);
 ok $schema->connection(
     DBICTest->_database,
     {
-        on_connect_do       => sub { $connected = 1 },
+        on_connect_do       => sub { $connected = 1; @cb_args = @_; },
         on_disconnect_do    => sub { $disconnected = 1 },
     },
 ), 'second connection()';
@@ -47,6 +47,7 @@ ok ! $disconnected, 'on_disconnect_do() not called after connect()';
 $schema->storage->disconnect();
 ok $disconnected, 'on_disconnect_do() called after disconnect()';
 
+isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
 
 sub check_exists {
     my $storage = shift;