=head1 SYNOPSIS
-Create a schema class called MyDB/Schema.pm:
+Create a schema class called MyApp/Schema.pm:
- package MyDB::Schema;
+ package MyApp::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces();
1;
Create a result class to represent artists, who have many CDs, in
-MyDB/Schema/Result/Artist.pm:
+MyApp/Schema/Result/Artist.pm:
See L<DBIx::Class::ResultSource> for docs on defining result classes.
- package MyDB::Schema::Result::Artist;
+ package MyApp::Schema::Result::Artist;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
- __PACKAGE__->has_many(cds => 'MyDB::Schema::Result::CD');
+ __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD');
1;
A result class to represent a CD, which belongs to an artist, in
-MyDB/Schema/Result/CD.pm:
+MyApp/Schema/Result/CD.pm:
- package MyDB::Schema::Result::CD;
+ package MyApp::Schema::Result::CD;
use base qw/DBIx::Class::Core/;
__PACKAGE__->load_components(qw/InflateColumn::DateTime/);
__PACKAGE__->table('cd');
__PACKAGE__->add_columns(qw/ cdid artistid title year /);
__PACKAGE__->set_primary_key('cdid');
- __PACKAGE__->belongs_to(artist => 'MyDB::Schema::Result::Artist', 'artistid');
+ __PACKAGE__->belongs_to(artist => 'MyApp::Schema::Result::Artist', 'artistid');
1;
Then you can use these classes in your application's code:
# Connect to your database.
- use MyDB::Schema;
- my $schema = MyDB::Schema->connect($dbi_dsn, $user, $pass, \%dbi_params);
+ use MyApp::Schema;
+ my $schema = MyApp::Schema->connect($dbi_dsn, $user, $pass, \%dbi_params);
# Query for all artists and put them in an array,
# or retrieve them as a result set object.
=head1 SYNOPSIS
## Creating relationships
- MyDB::Schema::Actor->has_many('actorroles' => 'MyDB::Schema::ActorRole',
+ MyApp::Schema::Actor->has_many('actorroles' => 'MyApp::Schema::ActorRole',
'actor');
- MyDB::Schema::Role->has_many('actorroles' => 'MyDB::Schema::ActorRole',
+ MyApp::Schema::Role->has_many('actorroles' => 'MyApp::Schema::ActorRole',
'role');
- MyDB::Schema::ActorRole->belongs_to('role' => 'MyDB::Schema::Role');
- MyDB::Schema::ActorRole->belongs_to('actor' => 'MyDB::Schema::Actor');
+ MyApp::Schema::ActorRole->belongs_to('role' => 'MyApp::Schema::Role');
+ MyApp::Schema::ActorRole->belongs_to('actor' => 'MyApp::Schema::Actor');
- MyDB::Schema::Role->many_to_many('actors' => 'actorroles', 'actor');
- MyDB::Schema::Actor->many_to_many('roles' => 'actorroles', 'role');
+ MyApp::Schema::Role->many_to_many('actors' => 'actorroles', 'actor');
+ MyApp::Schema::Actor->many_to_many('roles' => 'actorroles', 'role');
## Using relationships
$schema->resultset('Actor')->find({ id => 1})->roles();
An arrayref containing a list of accessors in the foreign class to create in
the main class. If, for example, you do the following:
- MyDB::Schema::CD->might_have(liner_notes => 'MyDB::Schema::LinerNotes',
+ MyApp::Schema::CD->might_have(liner_notes => 'MyApp::Schema::LinerNotes',
undef, {
proxy => [ qw/notes/ ],
});
-Then, assuming MyDB::Schema::LinerNotes has an accessor named notes, you can do:
+Then, assuming MyApp::Schema::LinerNotes has an accessor named notes, you can do:
- my $cd = MyDB::Schema::CD->find(1);
+ my $cd = MyApp::Schema::CD->find(1);
$cd->notes('Notes go here'); # set notes -- LinerNotes object is
# created if it doesn't exist
A hashref where each key is the accessor you want installed in the main class,
and its value is the name of the original in the fireign class.
- MyDB::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', {
+ MyApp::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', {
proxy => { cd_title => 'title' },
});
NOTE: you can pass a nested struct too, for example:
- MyDB::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', {
+ MyApp::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', {
proxy => [ 'year', { cd_title => 'title' } ],
});
# Create a table based result source, in a result class.
- package MyDB::Schema::Result::Artist;
+ package MyApp::Schema::Result::Artist;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
- __PACKAGE__->has_many(cds => 'MyDB::Schema::Result::CD');
+ __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD');
1;
# Create a query (view) based result source, in a result class
- package MyDB::Schema::Result::Year2000CDs;
+ package MyApp::Schema::Result::Year2000CDs;
use base qw/DBIx::Class::Core/;
__PACKAGE__->load_components('InflateColumn::DateTime');
=head1 SYNOPSIS
- package MyDB::Schema::Result::Year2000CDs;
+ package MyApp::Schema::Result::Year2000CDs;
use base qw/DBIx::Class::Core/;
=head1 EXAMPLES
-Having created the MyDB::Schema::Year2000CDs schema as shown in the SYNOPSIS
+Having created the MyApp::Schema::Year2000CDs schema as shown in the SYNOPSIS
above, you can then:
$2000_cds = $schema->resultset('Year2000CDs')
=head2 deploy_depends_on
__PACKAGE__->result_source_instance->deploy_depends_on(
- ["MyDB::Schema::Result::Year","MyDB::Schema::Result::CD"]
+ ["MyApp::Schema::Result::Year","MyApp::Schema::Result::CD"]
);
Specify the views (and only the views) that this view depends on.