X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=3992111565225020a0d5545a98fcf693cbbe4a55;hb=c13002976e32b818eabc3a8eaf6fa2e23ebed7e9;hp=7002b54ea6b865906073126270d05cfbfd07d7a0;hpb=cc31b05ca2b037cc0adce572568bce2bc5236b1d;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 7002b54..3992111 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -113,9 +113,8 @@ almost like you would define a regular ResultSource. package My::Schema::Result::UserFriendsComplex; use strict; use warnings; - use base qw/DBIx::Class/; + use base qw/DBIx::Class::Core/; - __PACKAGE__->load_components('Core'); __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); # ->table, ->add_columns, etc. @@ -318,7 +317,7 @@ Please see L documentation if you are in any way unsure about the use of the attributes above (C< join >, C< select >, C< as > and C< group_by >). -=head2 Subqueries (EXPERIMENTAL) +=head2 Subqueries You can write subqueries relatively easily in DBIC. @@ -366,10 +365,6 @@ That creates the following SQL: WHERE artist_id = me.artist_id ) -=head3 EXPERIMENTAL - -Please note that subqueries are considered an experimental feature. - =head2 Predefined searches You can write your own L class by inheriting from it @@ -391,11 +386,16 @@ and defining often used searches as methods: 1; -To use your resultset, first tell DBIx::Class to create an instance of it -for you, in your My::DBIC::Schema::CD class: +If you're using L, simply place the file +into the C directory next to your C directory, and it will +be automatically loaded. + +If however you are still using L, first tell +DBIx::Class to create an instance of the ResultSet class for you, in your +My::DBIC::Schema::CD class: # class definition as normal - __PACKAGE__->load_components(qw/ Core /); + use base 'DBIx::Class::Core'; __PACKAGE__->table('cd'); # tell DBIC to use the custom ResultSet class @@ -814,7 +814,7 @@ this example we have a single user table that carries a boolean bit for admin. We would like like to give the admin users objects (L) the same methods as a regular user but also special admin only methods. It doesn't make sense to create two -seperate proxy-class files for this. We would be copying all the user +separate proxy-class files for this. We would be copying all the user methods into the Admin class. There is a cleaner way to accomplish this. @@ -842,13 +842,11 @@ B use strict; use warnings; - use base qw/DBIx::Class/; + use base qw/DBIx::Class::Core/; ### Define what our admin class is, for ensure_class_loaded() my $admin_class = __PACKAGE__ . '::Admin'; - __PACKAGE__->load_components(qw/Core/); - __PACKAGE__->table('users'); __PACKAGE__->add_columns(qw/user_id email password @@ -1090,8 +1088,7 @@ If you want to get a filtered result set, you can just add add to $attr as follo This is straightforward using L: package My::User; - use base 'DBIx::Class'; - __PACKAGE__->load_components('Core'); + use base 'DBIx::Class::Core'; __PACKAGE__->table('user'); __PACKAGE__->add_columns(qw/id name/); __PACKAGE__->set_primary_key('id'); @@ -1099,8 +1096,7 @@ This is straightforward using Lmany_to_many('addresses' => 'user_address', 'address'); package My::UserAddress; - use base 'DBIx::Class'; - __PACKAGE__->load_components('Core'); + use base 'DBIx::Class::Core'; __PACKAGE__->table('user_address'); __PACKAGE__->add_columns(qw/user address/); __PACKAGE__->set_primary_key(qw/user address/); @@ -1108,8 +1104,7 @@ This is straightforward using Lbelongs_to('address' => 'My::Address'); package My::Address; - use base 'DBIx::Class'; - __PACKAGE__->load_components('Core'); + use base 'DBIx::Class::Core'; __PACKAGE__->table('address'); __PACKAGE__->add_columns(qw/id street town area_code country/); __PACKAGE__->set_primary_key('id'); @@ -1140,8 +1135,7 @@ To accomplish this one only needs to specify the DB schema name in the table declaration, like so... package MyDatabase::Main::Artist; - use base qw/DBIx::Class/; - __PACKAGE__->load_components(qw/PK::Auto Core/); + use base qw/DBIx::Class::Core/; __PACKAGE__->table('database1.artist'); # will use "database1.artist" in FROM clause @@ -1274,7 +1268,7 @@ row. my $schema = MySchema->connect("dbi:Pg:dbname=my_db"); # Start a transaction. Every database change from here on will only be - # commited into the database if the eval block succeeds. + # committed into the database if the eval block succeeds. eval { $schema->txn_do(sub { # SQL: BEGIN WORK; @@ -1327,7 +1321,7 @@ row. }; if ($@) { # There was an error while handling the $job. Rollback all changes - # since the transaction started, including the already commited + # since the transaction started, including the already committed # ('released') savepoints. There will be neither a new $job nor any # $thing entry in the database. @@ -1388,7 +1382,7 @@ MySQL, SQLite and PostgreSQL, using the $VERSION from your Schema.pm. To create a new database using the schema: my $schema = My::Schema->connect($dsn); - $schema->deploy({ add_drop_tables => 1}); + $schema->deploy({ add_drop_table => 1}); To import created .sql files using the mysql client: @@ -1426,8 +1420,7 @@ Make a table class as you would for any other table package MyAppDB::Dual; use strict; use warnings; - use base 'DBIx::Class'; - __PACKAGE__->load_components("Core"); + use base 'DBIx::Class::Core'; __PACKAGE__->table("Dual"); __PACKAGE__->add_columns( "dummy", @@ -2012,15 +2005,15 @@ details on creating static schemas from a database). Typically L result classes start off with - use base qw/DBIx::Class/; - __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); + use base qw/DBIx::Class::Core/; + __PACKAGE__->load_components(qw/InflateColumn::DateTime/); If this preamble is moved into a common base class:- package MyDBICbase; - use base qw/DBIx::Class/; - __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); + use base qw/DBIx::Class::Core/; + __PACKAGE__->load_components(qw/InflateColumn::DateTime/); 1; and each result class then uses this as a base:-