Merge 'trunk' into 'cdbicompat_integration'
Matt S Trout [Fri, 14 Sep 2007 20:42:29 +0000 (20:42 +0000)]
r11217@jules (orig r3705):  tomboh | 2007-08-22 11:28:58 +0100
Fix the behaviour of code refs within array refs for on_(dis)?connect_do
and enhance tests to spot the previous mistake.

r11218@jules (orig r3706):  tomboh | 2007-08-22 11:57:14 +0100
Add myself to the list of contributors

r11232@jules (orig r3709):  gphat | 2007-08-24 18:11:46 +0100
Fix typos.

r14025@jules (orig r3720):  ilmari | 2007-09-04 17:44:41 +0100
Fix return value for DBIC::ResultSource::Table->table($table)
r14026@jules (orig r3721):  ash | 2007-09-04 20:14:02 +0100
Bump for New relase
r14027@jules (orig r3722):  semifor | 2007-09-05 04:49:46 +0100
 r1185@titanic:  mjm | 2007-09-04 20:11:07 -0700
 Updated email address

r14029@jules (orig r3723):  castaway | 2007-09-06 21:07:52 +0100
Doc patch from wreis

r14030@jules (orig r3724):  castaway | 2007-09-06 22:35:49 +0100
Add more about accessors to doc

r14031@jules (orig r3725):  tomboh | 2007-09-07 17:54:00 +0100
Small POD fix

r14032@jules (orig r3726):  semifor | 2007-09-08 17:58:56 +0100
 r1191@titanic:  mjm | 2007-09-08 09:20:32 -0700
 discard_changes is also "refresh from storage"

r14035@jules (orig r3729):  castaway | 2007-09-12 00:23:20 +0100
Much doch shuffling and more argument explanations (due to initself ;)

14 files changed:
Changes
lib/DBIx/Class.pm
lib/DBIx/Class/Manual/FAQ.pod
lib/DBIx/Class/PK.pm
lib/DBIx/Class/Relationship.pm
lib/DBIx/Class/ResultClass/HashRefInflator.pm
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy/Table.pm
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/ODBC.pm
lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm
t/60core.t
t/92storage_on_connect_do.t

diff --git a/Changes b/Changes
index bf8a7ff..ccb5ded 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 Revision history for DBIx::Class
 
+0.08007 2007-09-04 19:36:00
         - patch for Oracle datetime inflation (abram@arin.net)
         - added on_disconnect_do
         - on_connect_do and on_disconnect_do take coderefs and arrayrefs
index 3f0fb8e..854df8e 100644 (file)
@@ -23,7 +23,7 @@ sub component_base_class { 'DBIx::Class' }
 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
 # brain damage and presumably various other packaging systems too
 
-$VERSION = '0.08006';
+$VERSION = '0.08007';
 
 sub MODIFY_CODE_ATTRIBUTES {
   my ($class,$code,@attrs) = @_;
@@ -265,6 +265,8 @@ sszabo: Stephan Szabo <sszabo@bigpanda.com>
 
 Todd Lipcon
 
+Tom Hukins
+
 typester: Daisuke Murase <typester@cpan.org>
 
 victori: Victor Igumnov <victori@cpan.org>
index 39f4b99..d372115 100644 (file)
@@ -285,6 +285,18 @@ Why slice instead of L<DBIx::Class::ResultSet/first> or L<DBIx::Class::ResultSet
 If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we
 really only need one row. This can result in a significant speed improvement.
 
+=item .. refresh a row from storage?
+
+Use L<DBIx::Class::PK/discard_changes>.
+
+  $row->discard_changes
+
+Discarding changes and refreshing from storage are two sides fo the same coin.  When you
+want to discard your local changes, just re-fetch the row from storage.  When you want
+to get a new, fresh copy of the row, just re-fetch the row from storage.
+L<DBIx::Class::PK/discard_changes> does just that by re-fetching the row from storage
+using the row's primary key.
+
 =back
 
 =head2 Inserting and updating data
@@ -398,6 +410,6 @@ you ask the resultset for an actual row object.
 particular column or group of columns (a-la cdbi Stringfy column
 group, or stringify_self method) ?
 
-See L<Cookbook/Stringification>
+See L<DBIx::Class::Manual::Cookbook/Stringification>
 
 =back
index 9b9f8a4..2a68df5 100644 (file)
@@ -30,6 +30,9 @@ sub _ident_values {
 Re-selects the row from the database, losing any changes that had
 been made.
 
+This method can also be used to refresh from storage, retrieving any
+changes made since the row was last read from storage.
+
 =cut
 
 sub discard_changes {
index b95867f..3ee93ff 100644 (file)
@@ -115,6 +115,44 @@ relationship attributes.
 
 =back
 
+Creates a relationship where the calling class stores the foreign class's
+primary key in one (or more) of its columns. This relationship defaults to
+using C<$accessor_name> as the foreign key in C<$related_class> to resolve the
+join, unless C<$foreign_key_column> specifies the foreign key column in
+C<$related_class> or C<$cond> specifies a reference to a join condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the instance of the foreign
+class matching this relationship.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table referenced by the foreign key in
+this class.
+
+=item foreign_key_column
+
+The column name on this class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
+
   # in a Book class (where Author has many Books)
   My::DBIC::Schema::Book->belongs_to( author => 'My::DBIC::Schema::Author' );
 
@@ -127,12 +165,6 @@ The above belongs_to relationship could also have been specified as,
                                       'My::DBIC::Schema::Author',
                                       { 'foreign.author' => 'self.author' } );
 
-Creates a relationship where the calling class stores the foreign class's
-primary key in one (or more) of its columns. This relationship defaults to
-using C<$accessor_name> as the foreign key in C<$related_class> to resolve the
-join, unless C<$foreign_key_column> specifies the foreign key column in
-C<$related_class> or C<$cond> specifies a reference to a join condition hash.
-
 If the relationship is optional -- i.e. the column containing the foreign key
 can be NULL -- then the belongs_to relationship does the right thing. Thus, in
 the example above C<$obj-E<gt>author> would return C<undef>.  However in this
@@ -163,6 +195,45 @@ methods and valid relationship attributes.
 
 =back
 
+Creates a one-to-many relationship, where the corresponding elements of the
+foreign class store the calling class's primary key in one (or more) of its
+columns. This relationship defaults to using C<$accessor_name> as the foreign
+key in C<$related_class> to resolve the join, unless C<$foreign_key_column>
+specifies the foreign key column in C<$related_class> or C<$cond> specifies a
+reference to a join condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve a resultset of the related
+class restricted to the ones related to the row object. In list
+context it returns the row objects.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table which contains a foreign key
+column containing PK values of this class.
+
+=item foreign_key_column
+
+The column name on the related class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
   # in an Author class (where Author has_many Books)
   My::DBIC::Schema::Author->has_many(books => 'My::DBIC::Schema::Book', 'author');
 
@@ -184,13 +255,6 @@ explicit join condition:
     'foreign.author' => 'self.author',
   });
 
-Creates a one-to-many relationship, where the corresponding elements of the
-foreign class store the calling class's primary key in one (or more) of its
-columns. This relationship defaults to using C<$accessor_name> as the foreign
-key in C<$related_class> to resolve the join, unless C<$foreign_key_column>
-specifies the foreign key column in C<$related_class> or C<$cond> specifies a
-reference to a join condition hash.
-
 Three methods are created when you create a has_many relationship.  The first
 method is the expected accessor method, C<$accessor_name()>.  The second is
 almost exactly the same as the accessor method but "_rs" is added to the end of
@@ -217,6 +281,43 @@ methods and valid relationship attributes.
 
 =back
 
+Creates an optional one-to-one relationship with a class. This relationship
+defaults to using C<$accessor_name> as the foreign key in C<$related_class> to
+resolve the join, unless C<$foreign_key_column> specifies the foreign key
+column in C<$related_class> or C<$cond> specifies a reference to a join
+condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the instance of the foreign
+class matching this relationship.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table which contains a foreign key
+column containing PK values of this class.
+
+=item foreign_key_column
+
+The column name on the related class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
   My::DBIC::Schema::Author->might_have( pseudonym =>
                                         'My::DBIC::Schema::Pseudonym' );
 
@@ -234,14 +335,6 @@ Or even:
                                         'My::DBIC::Schema::Pseudonym',
                                         { 'foreign.author' => 'self.author' } );
 
-Assuming the Pseudonym table has
-
-Creates an optional one-to-one relationship with a class. This relationship
-defaults to using C<$accessor_name> as the foreign key in C<$related_class> to
-resolve the join, unless C<$foreign_key_column> specifies the foreign key
-column in C<$related_class> or C<$cond> specifies a reference to a join
-condition hash.
-
 If you update or delete an object in a class with a C<might_have>
 relationship, the related object will be updated or deleted as well. To
 turn off this behavior, add C<< cascade_delete => 0 >> to the C<$attr>
@@ -287,6 +380,37 @@ methods and valid relationship attributes.
 
 =back
 
+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 
+resultset or collection of objects just like has_many does, you cannot call 
+C<related_resultset> and similar methods which operate on true relationships.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the rows matching this
+relationship.
+
+On a many_to_many, unlike other relationships, this cannot be used in
+L<DBIx::Class::ResultSet/search> to join tables. Use the relations
+bridged across instead.
+
+=item link_rel_name
+
+This is the accessor_name from the has_many relationship we are
+bridging from.
+
+=item foreign_rel_name
+
+This is the accessor_name of the belongs_to relationship in the link
+table that we are bridging across (which gives us the table we are
+bridging to).
+
+=back
+
 To create a many_to_many relationship from Actor to Role:
 
   My::DBIC::Schema::Actor->has_many( actor_roles =>
@@ -313,12 +437,6 @@ actor_roles table:
 
   $actor->add_to_roles($role, { year => 1995 });
 
-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 
-resultset or collection of objects just like has_many does, you cannot call 
-C<$related_resultset> and similar methods which operate on true relationships.
-
 In the above example, ActorRoles is the link table class, and Role is the
 foreign class. The C<$link_rel_name> parameter is the name of the accessor for
 the has_many relationship from this table to the link table, and the
index 9a2c8eb..6ad22ad 100644 (file)
@@ -23,13 +23,13 @@ There are two ways of using this class.
 =item *
 
 Specify C<< $rs->result_class >> on a specific resultset to affect only that
-resultser (and any chained off of it); or
+resultset (and any chained off of it); or
 
 =item *
 
 Specify C<< __PACKAGE__->result_class >> on your source object to force all
 uses of that result source to be inflated to hash-refs - this approach is not
-recomended
+recommended.
 
 =back
 
index ff3dce6..636754b 100644 (file)
@@ -2217,11 +2217,10 @@ Indicates additional column names for those added via L<+select>.
 
 =back
 
-Indicates column names for object inflation. That is, c< as >
+Indicates column names for object inflation. That is, C<as>
 indicates the name that the column can be accessed as via the
 C<get_column> method (or via the object accessor, B<if one already
-exists>).  It has nothing to do with the SQL code C< SELECT foo AS bar
->.
+exists>).  It has nothing to do with the SQL code C<SELECT foo AS bar>.
 
 The C<as> attribute is used in conjunction with C<select>,
 usually when C<select> contains one or more function or stored
index 8c40b36..d21cdb7 100644 (file)
@@ -81,6 +81,10 @@ 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
 method will add more columns, not replace them.
 
+The column names given will be created as accessor methods on your
+L<DBIx::Class::Row> objects, you can change the name of the accessor
+by supplying an L</accessor> in the column_info hash.
+
 The contents of the column_info are not set in stone. The following
 keys are currently recognised/used by DBIx::Class:
 
@@ -88,7 +92,7 @@ keys are currently recognised/used by DBIx::Class:
 
 =item accessor
 
-Use this to set the name of the accessor for this column. If unset,
+Use this to set the name of the accessor method for this column. If unset,
 the name of the column will be used.
 
 =item data_type
index 474c330..61b53fa 100644 (file)
@@ -99,6 +99,7 @@ sub table {
     $class =~ m/([^:]+)$/;
     $class->schema_instance->register_class($class, $class);
   }
+  return $class->result_source_instance->name;
 }
 
 =head2 has_column
index 2b7672a..d8d918d 100644 (file)
@@ -366,7 +366,7 @@ array reference, its return value is ignored.
 
 =item on_disconnect_do
 
-Takes arguments in the same for as L<on_connect_do> and executes them
+Takes arguments in the same form as L<on_connect_do> and executes them
 immediately before disconnecting from the database.
 
 Note, this only runs if you explicitly call L<disconnect> on the
@@ -792,7 +792,8 @@ sub _do_query {
   my ($self, $action) = @_;
 
   if (ref $action eq 'CODE') {
-    $action->($self);
+    $action = $action->($self);
+    $self->_do_query($_) foreach @$action;
   }
   else {
     my @to_run = (ref $action eq 'ARRAY') ? (@$action) : ($action);
index 42466ef..d7b4509 100644 (file)
@@ -39,7 +39,7 @@ for a specific ODBC backend.  It should be transparent to the user.
 
 =head1 AUTHORS
 
-Marc Mims C<< <marc@sssonline.com> >>
+Marc Mims C<< <marc@questright.com> >>
 
 =head1 LICENSE
 
index 1df4c21..5b8b348 100644 (file)
@@ -56,7 +56,7 @@ for connections using either SQL naming or System naming.
 
 =head1 AUTHORS
 
-Marc Mims C<< <marc@sssonline.com> >>
+Marc Mims C<< <marc@questright.com> >>
 
 Based on DBIx::Class::Storage::DBI::DB2 by Jess Robinson.
 
index 2f3339e..456dc7b 100644 (file)
@@ -7,7 +7,7 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 77;
+plan tests => 78;
 
 eval { require DateTime::Format::MySQL };
 my $NO_DTFM = $@ ? 1 : 0;
@@ -337,3 +337,10 @@ SKIP: {
     is($edata{'created_on'}, $event->created_on, 'got created date');
 }
 
+# test resultsource->table return value when setting
+{
+    my $class = $schema->class('Event');
+    diag $class;
+    my $table = $class->table($class->table);
+    is($table, $class->table, '->table($table) returns $table');
+}
index 0c35923..62712af 100644 (file)
@@ -17,6 +17,7 @@ ok $schema->connection(
         on_connect_do       => [
             'CREATE TABLE TEST_empty (id INTEGER)',
             [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
+            \&insert_from_subref,
         ],
         on_disconnect_do    =>
             [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
@@ -25,7 +26,7 @@ ok $schema->connection(
 
 is_deeply
   $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
-  [ [ 2 ] ],
+  [ [ 2 ], [ 3 ], [ 7 ] ],
   'on_connect_do() worked';
 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
 ok $@, 'Searching for nonexistent table dies';
@@ -50,10 +51,20 @@ ok $disconnected, 'on_disconnect_do() called after disconnect()';
 sub check_exists {
     my $storage = shift;
     ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
+    return;
 }
 
 sub check_dropped {
     my $storage = shift;
     eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
     ok $@, 'Reading from dropped table fails';
+    return;
+}
+
+sub insert_from_subref {
+    my $storage = shift;
+    return [
+        [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
+        'INSERT INTO TEST_empty VALUES (7)',
+    ];
 }