[Catalyst] Doing work inside the DBIx::Class model

Toby Corkindale tjc at wintrmute.net
Wed Feb 20 03:18:24 GMT 2008


On Wed, Feb 20, 2008 at 01:10:12PM +1000, Cian Barclay wrote:
> Hello Catalysters,
> 
> I'm using Catalyst with a DBIx::Class model generated by
> DBIx::Class::Schema::Loader.
> 
> I want to make my model do more work, rather than having my
> controllers fiddling around with model objects doing things to them.
> But I'm stuck on the bit where I want to get a resultset inside the
> model's subroutines. In a controller I use $c->model("Foo::Bar") to
> get the resultset. How can I get a resultset when I'm in the model?
> 
> I could pass $c in to the model, but then the model wouldn't be
> usable without Catalyst. I'd like to be able to use the model
> for other things, but from reading the DBIx::Class manual, it
> seems like I'd need the $schema object to get resultsets.
> 
> Since I'm stuck, I thought it would be a good time to ask for some
> help on this please. Is there a way to make a DBIx::Class model
> which is usable both for Catalyst and something else? How do you
> get resultsets inside the model which could either be from the
> Catalyst model, or from the database connection if Catalyst wasn't
> being used?

I think you're looking for the $self->resultsource->schema method, inside your
Model?

tjc.



More information about the Catalyst mailing list