[Catalyst] Using a model class from other class

Tomas Doran bobtfish at bobtfish.net
Sat Oct 1 10:37:44 GMT 2011


On 29 Sep 2011, at 18:36, Nicholas Wehr wrote:

> perhaps a simple way:
>
> my $rs = $c->model("DB::Group")->all;
> while (my $group = $rs->next) {
>        for my $user ($ group->users ) {
>      # do stuff
>        }
> }
>

Less good - this is implying that the code goes into the controller  
layer, whereas this looks like an operation that should be performed  
in the data model.

I.e. $c->model("DB::Group")->do_stuff_to_all_groups(%data);

or similar, so putting the code in the DBIC layer is entirely  
appropriate and gives you much nicer separation of concerns, as the  
controller knows nothing about the specifics of how the operation it  
requests is performed.

Cheers
t0m




More information about the Catalyst mailing list