[Catalyst] How to access DBIC schema from class method?

seasprocket at gmail.com seasprocket at gmail.com
Wed Aug 11 21:55:20 GMT 2010


Ah, okay, I get it. Thank you!!

On Wed, Aug 11, 2010 at 1:06 AM, Moritz Onken <onken at houseofdesign.de>wrote:

> Hi,
>
> you need to move this in the resultset class:
>
> package MyApp::Schema::ResultSet::User;
> use base 'DBIx::Class::ResultSet';
> ...
>
> sub create_user {
>    my ($rs, $params) =3D @_;
>    return $rs->create({});
> }
>
> then you can access it via $c->model('DB::User')->create_user($params)
>
>
> cheers,
> mo
>
> Am 11.08.2010 um 02:57 schrieb seasprocket at gmail.com:
>
> > I'm confused about the "right" way to get a schema instance from within=
 a
> class method. If I've already got a resultset or resultsource instance, i=
t's
> easy. But from a class method within my model? Do I create a new connecti=
on
> every time I need one, ie. MyApp::Schema->connect()?
> >
> > To be specific:
> >
> > package MyApp::Schema::Result::User;
> > use base 'DBIx::Class::Core';
> > ...
> >
> > sub create_user {
> >     my ($class, $params) =3D @_;
> >     # Want to call $user_rs->create() here after I've validated data.
> >     # my $schema =3D MyApp::Schema->connect()?
> > }
> >
> > My suspicion is that this should be an instance method, bc it represents
> the table, not a user object. And the way to get an instance is to call
> $rs->result_source on a result set. But when I call:
> >       $c->model('DB::User')->result_source->create_user($params) it fai=
ls
> with the msg:
> >
> > Can't locate object method "create_user" via package
> "DBIx::Class::ResultSource::Table"
> >
> >
> >
> >
> >
> >
> > --
> > Bikewise: http://www.bikewise.org
> >
> > _______________________________________________
> > List: Catalyst at 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/
>
>
> _______________________________________________
> List: Catalyst at 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/
>



-- =

Bikewise: http://www.bikewise.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100811/9315e=
321/attachment.htm


More information about the Catalyst mailing list