From: Rafael Kitover Date: Fri, 24 Dec 2010 12:53:11 +0000 (+0100) Subject: Consistently use MyApp::Schema throught the documentation X-Git-Tag: v0.08191~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=03460bef425a7626fc5e3ce4b25b66fa347f5c23;p=dbsrgits%2FDBIx-Class.git Consistently use MyApp::Schema throught the documentation --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 6fb4760..75d97fc 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -124,9 +124,9 @@ The community can be found via: =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(); @@ -134,39 +134,39 @@ Create a schema class called MyDB/Schema.pm: 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 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. diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 29a7ffc..d4141d1 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -20,15 +20,15 @@ DBIx::Class::Relationship - Inter-table relationships =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(); diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 506d51d..afb7dd4 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -256,14 +256,14 @@ command immediately before C. 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 @@ -272,7 +272,7 @@ Then, assuming MyDB::Schema::LinerNotes has an accessor named notes, you can do: 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' }, }); @@ -282,7 +282,7 @@ This will create an accessor named C on the C<$track> row object. 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' } ], }); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 0d8bbf5..0e9d1bd 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -31,18 +31,18 @@ DBIx::Class::ResultSource - Result source object # 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'); diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index c053009..9c0d51a 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -16,7 +16,7 @@ DBIx::Class::ResultSource::View - ResultSource object representing a view =head1 SYNOPSIS - package MyDB::Schema::Result::Year2000CDs; + package MyApp::Schema::Result::Year2000CDs; use base qw/DBIx::Class::Core/; @@ -63,7 +63,7 @@ case replaces the view name in a FROM clause in a subselect. =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') @@ -132,7 +132,7 @@ syntaxes. =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.