[Catalyst] Best practices for extending DBIC model

Eric Wright ewright at linescale.com
Thu Jul 14 13:58:48 GMT 2011


Any input/comments on best practices for extending a DBIC model? I have a
DBIC schema that for the most part does what I need it to do. I find where I
need model specific enhancements I can easily extend the schema objects
themselves keeping the data centric code out of my controller layer. What
I'm struggling with is how best to handle things at a higher level - i.e.
modifying the resultsets themselves.

e.g. say I have a Clients table and I want to get *all* clients in the
system and then massage them in some way. I cannot do this with simple SQL
or DBIC joins. I can extend Clients.pm for level stuff but what I really
need is a way to extend the DBIx::Class::ResultSet object that is returned
by $c->model('DB::Clients') so that that I can perform something like the
following:

my @clients =3D $c->model('DB::Clients')->grouped_clients;

I'm using Catalyst::Model::DBIC::Schema. Is there a preferred way to hook
into the result set to customize things the way I need?

Or do I just create a new model altogether and call the schema from that
model?

my @clients =3D $c->model('MyNewModel')->grouped_clients;

I dunno. The second method just seems a little kludgey to me unless I make
it a complete wrapper around my DBIC schema. Any insight into how you guys
build your apps would be most appreciated.

Thanks!
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110714/f3479=
d4a/attachment.htm


More information about the Catalyst mailing list