Catalyst::Model::DBIC::Schema

DBIx::Class::Schema Model Class
Download

Catalyst::Model::DBIC::Schema Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Rafael Kitover
  • Publisher web site:
  • http://search.cpan.org/~rkitover/

Catalyst::Model::DBIC::Schema Tags


Catalyst::Model::DBIC::Schema Description

DBIx::Class::Schema Model Class Catalyst::Model::DBIC::Schema is a Catalyst Model for DBIx::Class::Schema-based Models. See the documentation for Catalyst::Helper::Model::DBIC::Schema 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->model('FilmDB') is NOT itself a DBIC schema or resultset object, but merely a wrapper proving methods 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 ACCEPT_CONTEXT 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');In order to add methods to a DBIC resultset, you cannot simply add them to the source (row, table) definition class; you must define a separate custom resultset class. See "Predefined searches" in DBIx::Class::Manual::Cookbook for more info. SYNOPSISManual creation of a DBIx::Class::Schema and a Catalyst::Model::DBIC::Schema: 1. Create the DBIx:Class schema in MyApp/Schema/FilmDB.pm: package MyApp::Schema::FilmDB; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes(qw/Actor Role/); 2. Create some classes for the tables in the database, for example an Actor in MyApp/Schema/FilmDB/Actor.pm: package MyApp::Schema::FilmDB::Actor; use base qw/DBIx::Class/ __PACKAGE__->load_components(qw/Core/); __PACKAGE__->table('actor'); ... and a Role in MyApp/Schema/FilmDB/Role.pm: package MyApp::Schema::FilmDB::Role; use base qw/DBIx::Class/ __PACKAGE__->load_components(qw/Core/); __PACKAGE__->table('role'); ... Notice that the schema is in MyApp::Schema, not in MyApp::Model. This way it's usable as a standalone module and you can test/run it without Catalyst. 3. To expose it to Catalyst as a model, you should create a DBIC Model in MyApp/Model/FilmDB.pm: package MyApp::Model::FilmDB; use base qw/Catalyst::Model::DBIC::Schema/; __PACKAGE__->config( schema_class => 'MyApp::Schema::FilmDB', connect_info => { dsn => "DBI:...", user => "username", password => "password", } ); Requirements: · Perl


Catalyst::Model::DBIC::Schema Related Software