=back
-If you are also using a L<DBIx::Class::PK::Auto> component, please
-make sure you load it correctly. Refer to
-L<DBIx::Class::PK::Auto/DESCRIPTION> for more information.
-
=head1 AUTHORS
Matt S. Trout <mst@shadowcatsystems.co.uk>
__PACKAGE__->load_components(qw/Core DB/);
If you want serial/auto-incrementing primary keys, you should use the
-L<DBIx::Class::PK::Auto> component for your database. For example, if
-you're using SQLite add C<PK::Auto::SQLite> to the list:
-
- __PACKAGE__->load_components(qw/PK::Auto::SQLite Core DB/);
+L<DBIx::Class::PK::Auto> component.
+ __PACKAGE__->load_components(qw/PK::Auto Core DB/);
C<PK::Auto> classes exist for many databases; see
L<DBIx::Class::PK::Auto> for more information.
Load any components required by each class with the load_components() method.
This should consist of "Core" plus any additional components you want to use.
-For example, if you use SQLite and want serial/auto-incrementing primary keys:
+For example, if you want serial/auto-incrementing primary keys:
- __PACKAGE__->load_components(qw/ PK::Auto::SQLite Core /);
+ __PACKAGE__->load_components(qw/ PK::Auto Core /);
C<PK::Auto> classes exist for many databases; see
L<DBIx::Class::PK::Auto> for more information.
=head1 SYNOPSIS
- # In your table classes (replace PK::Auto::SQLite with your database)
- __PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
- __PACKAGE__->set_primary_key('id');
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->set_primary_key('id');
=head1 DESCRIPTION
This class overrides the insert method to get automatically incremented primary
keys.
-You don't want to be using this directly - instead load the appropriate one for
-your database, e.g. C<PK::Auto::SQLite>, in your table classes:
+ __PACKAGE__->load_components(qw/PK::Auto Core/);
- __PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
-
-Note that C<PK::Auto::SQLite> is specified as the leftmost argument.
-
-Alternatively, you can load the components separately:
-
- __PACKAGE__->load_components(qw/Core/);
- __PACKAGE__->load_components(qw/PK::Auto::SQLite/);
-
-This can be used, for example, if you have different databases and need to
-determine the appropriate C<PK::Auto> class at runtime.
+Note that C<PK::Auto> is specified as the leftmost argument.
=head1 LOGIC
return $self->schema->source($self->relationship_info($rel)->{source});
}
+=head2 related_class
+
+=head3 Arguments: ($relname)
+
+Returns the class object for the given relationship
+
+=cut
+
+sub related_class {
+ my ($self, $rel) = @_;
+ if( !$self->has_relationship( $rel ) ) {
+ $self->throw_exception("No such relationship '$rel'");
+ }
+ return $self->schema->class($self->relationship_info($rel)->{source});
+}
+
=head2 resultset
Returns a resultset for the given source, by calling:
package Library::Schema::CD;
use base qw/DBIx::Class/;
- __PACKAGE__->load_components(qw/PK::Auto::Pg Core/); # for example
+ __PACKAGE__->load_components(qw/PK::Auto Core/); # for example
__PACKAGE__->table('cd');
# Elsewhere in your code:
=head3 Arguments: <target> <@db_info>
-This is the most important method in this class. it takes a target namespace,
-as well as dbh connection info, and creates a L<DBIx::Class::DB> class as
-well as subclasses for each of your database classes in this namespace, using
-this connection.
+This method takes a target namespace, as well as dbh connection info,
+and creates a L<DBIx::Class::DB> class as well as subclasses for each of
+your database classes in this namespace, using this connection.
It will also setup a ->class method on the target class, which lets you
resolve database classes based on the schema component name, for example
return $schema;
}
+=head2 compose_namespace
+
+=head3 Arguments: <target> <base>
+
+Translates <base> namespace into the specified <target> namespace.
+
+=cut
+
sub compose_namespace {
my ($self, $target, $base) = @_;
my %reg = %{ $self->source_registrations };
=head1 SYNOPSIS
# In your table classes
- __PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
+ __PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->set_primary_key('id');
=head1 DESCRIPTION
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto::SQLite CDBICompat Core DB/);
+__PACKAGE__->load_components(qw/PK::Auto CDBICompat Core DB/);
use File::Temp qw/tempfile/;
my (undef, $DB) = tempfile();