X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FModel%2FDBIC%2FSchema.pm;h=e44324e875bd4cd4b7668506a2acbd557e22dafc;hb=d52bc376e64d1ef6a50d0356290a55804f766ce1;hp=a44f2f04991e1952c7094a58181200da45fcf5b5;hpb=b9a72351503ce9856a5d201ca6f8fc917962e42a;p=catagits%2FCatalyst-Model-DBIC-Schema.git diff --git a/lib/Catalyst/Model/DBIC/Schema.pm b/lib/Catalyst/Model/DBIC/Schema.pm index a44f2f0..e44324e 100644 --- a/lib/Catalyst/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Model/DBIC/Schema.pm @@ -3,7 +3,7 @@ package Catalyst::Model::DBIC::Schema; use strict; use warnings; -our $VERSION = '0.20'; +our $VERSION = '0.22'; use base qw/Catalyst::Model Class::Accessor::Fast Class::Data::Accessor/; use NEXT; @@ -102,10 +102,10 @@ Authentication::Store::DBIC in MyApp.pm: password_field => 'password' } -C<< $c->model() >> returns a L for the source name -parameter passed. To find out more about which methods can be called on a -ResultSet, or how to add your own methods to it, please see the ResultSet -documentation in the L distribution. +C<< $c->model('Schema::Source') >> returns a L for +the source name parameter passed. To find out more about which methods can +be called on a ResultSet, or how to add your own methods to it, please see +the ResultSet documentation in the L distribution. Some examples are given below: @@ -143,6 +143,38 @@ This is a Catalyst Model for L-based Models. See the documentation for L for information on generating these Models via Helper scripts. +When your Catalyst app starts up, a thin Model layer is created as an +interface to your DBIC Schema. It should be clearly noted that the model +object returned by C<< $c->model('FilmDB') >> is NOT itself a DBIC schema or +resultset object, but merely a wrapper proving L to access +the underlying schema. + +In addition to this model class, a shortcut class is generated for each +source in the schema, allowing easy and direct access to a resultset of the +corresponding type. These generated classes are even thinner than the model +class, providing no public methods but simply hooking into Catalyst's +model() accessor via the +L mechanism. The complete +contents of each generated class is roughly equivalent to the following: + + package MyApp::Model::FilmDB::Actor + sub ACCEPT_CONTEXT { + my ($self, $c) = @_; + $c->model('FilmDB')->resultset('Actor'); + } + +In short, there are three techniques available for obtaining a DBIC +resultset object: + + # the long way + my $rs = $c->model('FilmDB')->schema->resultset('Actor'); + + # using the shortcut method on the model object + my $rs = $c->model('FilmDB')->resultset('Actor'); + + # using the generated class directly + my $rs = $c->model('FilmDB::Actor'); + =head1 CONFIG PARAMETERS =over 4 @@ -196,6 +228,28 @@ Examples: } ], +Or using L: + + + schema_class MyApp::Schema::FilmDB + connect_info dbi:Pg:dbname=mypgdb + connect_info postgres + connect_info + + AutoCommit 0 + on_connect_do some SQL statement + on_connect_do another SQL statement + + + +or + + + schema_class MyApp::Schema::FilmDB + connect_info dbi:SQLite:dbname=foo.db + + + =item storage_type Allows the use of a different C than what is set in your @@ -279,8 +333,8 @@ sub new { } else { croak "Either ->config->{connect_info} must be defined for $class" - . " or $schema_class must have connect info defined on it" - . "Here's what we got:\n" + . " or $schema_class must have connect info defined on it." + . " Here's what we got:\n" . Dumper($self); } }