[Catalyst] How do I use use DBIx::Class::Schema and Catalyst

Andreas Marienborg omega at palle.net
Tue Feb 7 11:26:18 CET 2006


On 5. feb. 2006, at 22.01, Alex Kavanagh wrote:

> Hi
>
> On the DBIx mailing list it has been announced that
> DBIx::Class::Loader has been deprecated in favour of
> DBIx::Class::Schema::Loader.
>

So I've heard :)

> I've been using the DBIx::Class::Loader and I'm wondering how to tie
> the Schema stuff into Catalyst.  I think I'd like to do it manually
> rather than use D::C::S::Loader because then I might actually learn
> DBIx properly!
>

I decided to use the Schema::Loader for now, but the rest of my info  
might be of good use :) We will see I guess.

Firstly, my "base" model looks like this.

---snip---
package Mediaflex::SMS::Model::ABook;

use strict;
use warnings;
use base 'DBIx::Class::Schema::Loader';

__PACKAGE__->load_from_connection(
     dsn             => Mediaflex::SMS->config->{addressbook}{dsn},
     relationships   => 1,
     options         => { AutoCommit => 1},
     inflect         => { child => 'children'},
);
1;
---snip---

and that seems to load the database properly.

Then to use it I had to change the way I refer to the classes a bit.

Usually I did

$c->model('ABook::Person')->find(<id>);

but now instead I have to do it like this:

$c->model('ABook')->resultset('Person')->find(<id>);

so a bit more typing, but if the Schema stuff is cool, I guess its  
worth it :)


hope that helps to get you started, but as for setting up the schema  
your self, I have no experience. Might be worth it running the Loader  
with debug => 1 to see what it does?


andreas




More information about the Catalyst mailing list