[Catalyst] Model/Controller logic separation - best practices?

Ian Sillitoe catalyst at sillit.com
Tue Mar 4 19:35:37 GMT 2008


Hopefully there is a quick and obvious answer to the following - if so,
apologies for the length of this email. Apologies in advance also if this is
considered off-topic and/or covered in previous threads - I have trawled
around for a while (and recently got Jonathan's book !) but all my solutions
seem a bit like hacks and I'm hoping for a "Best Practice".

My problem: given a row from table A, I would like to be able to return
related entries from table B ideally from within a template (unless this is
committing some kind of MVC heresy), I was thinking something like the
following:

Controller/TableA.pm:
$c->{stash}->{row_a} =3D $c->model('MyDBIC::TableA')->find('id');
$c->{stash}->{template} =3D 'view_a.tt2';
$c->forward('Catalyst::View::TT');

/root/src/view_a.tt2:
[% rows_b =3D row_a.get_related_rows( optional =3D> param ) %]
[% FOREACH row_b =3D rows_b %]
  [% DisplayRow(row_b) %]
[% END %]

However, there is a reasonable amount of logic required to get the related
rows - the relationship between A and B is too complicated to encapsulate in
a static "has_many" (especially with the optional params) so I can't use
"row_a.search_related()". Assuming this is the case (rather than my DBIC
incompetence):

1) where is the best place to put this logic? (Controller::ModelA.pm, DBIC::
ModelA.pm, ResultSet::ModelA.pm??)

2) following from 1) what is the best way of accessing this logic from the
template?

Many thanks,

Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080304/13de5=
d11/attachment.htm


More information about the Catalyst mailing list