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? Any help would be appreciated. For example: package Foo::Controller::Bars; sub do_something : Local { my ($self, $c) = @_; my $bar = $c->model("Foo::Bar")->find(77); $bar->set_widgets; } #----- package Foo::Bar; sub set_widgets { my $self = shift; # here I want to use $c->model("Foo::Widget") so that I can # create or select widgets. But I have no $c. # # If the model was used by something non-Catalyst, presumably # there would need to be some way of getting resultsets here # from the other application too. my $widget_rs = $something->model("Foo::Widget"); my $widget = $widget_rs->find_or_create({name => 'foobar'}); $self->widget($widget); $self->update; } #-----
_______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/