FAQ
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
moseley@hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110429/6b1c3f68/attachment.htm

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 29, '11 at 9:05p
activeApr 29, '11 at 9:05p
posts1
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

Bill Moseley: 1 post

People

Translate

site design / logo © 2022 Grokbase