[Dbix-class] Schema::Loader and has_many
Brandon Black
blblack at gmail.com
Thu Mar 23 01:32:50 CET 2006
On 3/22/06, Vsevolod (Simon) Ilyushchenko <simonf at cshl.edu> wrote:
> Brandon,
>
> So I got the relationships to work, but now I'm trying to turn on
> session support via Catalyst::Plugin::Session::Store::DBIC, and it's
> seems incompatible with the Loader. The test script t/05dbic-schema.t
> seems to be using schemas, but not the loader, and I can't reconcile the
> two.
>
A Schema generated by Schema::Loader and a Schema generated by hand
should be compatible for all practical purposes. Schema::Loader
merely subclasses Schema and fills in the table data for you when you
ask it to.
> Here's the furthest I've gotten - Catalyst::Model::DBIC::Schema->new
> should create the method ACCEPT_CONTEXT in the model class, which
> enables Session::Store::DBIC to work properly. This method is created on
> line 188.
>
> For the script t/05dbic-schema.t, the value of $class is
> 'TestApp::Model::DBICSchema', and the value of $moniker is 'Session', so
> the method is created in TestApp::Model::DBICSchema::Sesion. (The
> TestApp code is in the t/lib subdirectory of
> Catalyst::Plugin::Session::Store::DBIC).
>
> In my app at this point, $class is 'CSHL::Cat::Proto::M::Session', and
> $moniker iterates over all my model class names, including 'Session', so
> the ACCEPT_CONTEXT is uselessly created in
> 'CSHL::Cat::Proto::M::Session::Session' etc.
>
None of this made much sense to me, but ACCEPT_CONTEXT is not required
of Model classes.
> The difference between the applications is that I have the recommended
> setup of App::Schema.pm, App::Schema::Session.pm and App::M::Session.pm
> (which is ISA Catalyst::Model::DBIC::Schema, as recommended). While
> TestApp::Model::DBIC::Session is ISA TestApp::Model::DBIC, plus they
> have TestApp::Model::DBICSchema, which is ISA
> Catalyst::Model::DBIC::Schema.
>
The recommended setup if you're using Catalyst::Model::DBIC::Schema +
DBIx::Class::Schema::Loader is (as far as I can tell):
create appropriate session table in DB.
App/Schema.pm (ISA DBIx::Class::Schema::Loader)
App/M/DBIC.pm (ISA Catalyst::Model::DBIC::Schema, whose schema_class
is App::Schema)
And then dbic_class in Catalyst::Plugin::Session::Store::DBIC config
should be literally 'DBIC::Session' (which is the model name of your
table class, like you would use it in catalyst, e.g.
$c->model('DBIC::Session'). No other files or classes or hacks should
be neccesary.
-- Brandon
More information about the Dbix-class
mailing list