Hi,
when Catalyst::Model::DBIC::Schema is in use, you get this for free.
I assume that your sub-modules match your database tables. In that case,
you will have
Thingy::Schema::Result::User,
Thingy::Schema::Result::Team and
Thingy::Schema::Result::Incident.
You can access them like this:
my $users = $c-model(DB::User);
Now you can edit lib/Thingy/schema/Result/User.pm and add your
user-related code.
If you need code which operates on a resultset, instead of a single row,
you can create and/or edit Thingy::Schema::Resultset::User.
If you want to create your own Model for some reason, I suggest you to
take a look at Catalyst::Model::Adaptor.
There are tons of examples in Catalyst::Manual::Tutorial,
DBIx::Class::Manual and DBIx::Class::Tutorial (I haven't read the last one)
I am sure that the Catalyst manual contains a section about passing
configuration to the model, and that the DBIC manual will teach you how
to manually add modules to the schema.
To deploy shared code to several result classes, you can use Moose,
MooseX::NonMoose and Moose::Role, which have their own manuals.
cheers, Lukas
On 12/19/2012 06:53 PM, will trillich wrote:
Spent a bit of time googlilng this and apparnelty I'm not searching very
effectively today...
Short version:
What's best-practices to get model library sub-modules hooked in to the
main model?
Long version:
*catalyst.pl http://catalyst.pl Thingy*
*cd Thingy*
*script/thingy_create.pl http://thingy_create.pl model DB DBIC::Schema \*
* Thingy::Schema::DB create=static dbi:mysql:thingy \
*
* dbuser dbpasswd*
So now we have lib/Thingy/Model/DB like so:
*package Thingy::Model::DB;*
*
*
*use strict;*
*use base 'Catalyst::Model::DBIC::Schema';*
*
*
*__PACKAGE__-config(*
*schema_class = 'Thingy::Schema::DB',*
* *
*connect_info = {*
*dsn = 'dbi:mysql:thingy',*
*user = 'dbuser',*
*password = 'dbpasswd',*
*}*
*);*
This is a top-level module. Instead of a monolithic mess with all
possible library routines in one package, we want to modularize
sub-functions into, say
*Thingy::Model::DB::Team*
*Thingy::Model::DB::User*
*Thingy::Model::DB::Incident*
etc
Do we have those sub-modules use the top-level Thingy::Model::DB? Do
we have Thingy::Model::DB use the sub-modules?
Do we have the sub-modules use base 'Catalyst::Model::DBIC::Schema'?
Or can they just extends 'Catalyst::Model' and if so how do they hook
in with $c?
Is there an elegant way to have all the sub-module models use the same
DB config as the top model?
...or...
What's the best practice for getting separate modules to work as models
in the MVC universe?
--
Will Trillich :: 812.454.6431
“Grading takes away all the fun from failing. And a huge part of
education is about failure.” -- Shimon Schocken
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/