I'm not sure if this is more of a DBIC question or a Catalyst question.

I have two Catalyst::Model::DBIC::Schema model classes called
"App::Model::Foo" and "App::Model::Bar" configured to use two different
schema classes.  The databases are not exactly the same but both DBIC schema
classes expose the same methods needed for some actions.  That is, a
Foo::User and Bar::User object look similar and both have all the methods
that an action might end up calling on a user object.  But, the actual
database schema might different between the two -- different table name or
different set of columns.

The existing controllers use $c->model( 'Foo::User' ), for example.  So,
what I need is a way to switch models based on some value in the request
(e.g. inspecting the Host header) to $c->model( 'Bar::User' ).


I could use this rather crude approach:

around model => sub {
    my $model = shift;
    my $self = shift;
    my $type = shift;

    $type =~ /^Foo/Bar/ if $self->request->header( 'Host' ) =~
/$bar_host_re/;

    return $self->$model( $type, @_ );
};


Is there a better approach for selecting different models?  I suppose
another way would be to have App::Model::Foo select the schema class to
return.

Thanks,


-- 
Bill Moseley
[email protected]
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to