<div>I&#39;m not sure if this is more of a DBIC question or a Catalyst question.</div><div><br></div>I have two Catalyst::Model::DBIC::Schema model classes called &quot;App::Model::Foo&quot; and &quot;App::Model::Bar&quot; 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.<div>

<br></div><div>The existing controllers use $c-&gt;model( &#39;Foo::User&#39; ), 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-&gt;model( &#39;Bar::User&#39; ).</div>

<div><br></div><div><br></div><div>I could use this rather crude approach:</div><div><br></div><div>around model =&gt; sub {<br>    my $model = shift;<br>    my $self = shift;<br>    my $type = shift;<br><br>    $type =~ /^Foo/Bar/ if $self-&gt;request-&gt;header( &#39;Host&#39; ) =~ /$bar_host_re/;<br>

<br>    return $self-&gt;$model( $type, @_ );<br>};</div><div><br></div><div><br></div><div>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.</div>

<div><br></div><div>Thanks,<br><div><br></div><div><br></div><div>-- <br>Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a><br>
</div></div>