[Catalyst] fetching a model instance from a model instance

Dermot paikkos at googlemail.com
Thu Oct 27 11:50:21 GMT 2011


On 27 October 2011 12:26, Csongor Fagyal <concept at conceptonline.hu> wrote:
> Hi,
>
> Hello Fragzal,
> a Result basicly represents a single row, while ResultSet is an object which
> represents a database query.
> Your should put your confirmAndGetUser method into
> MyApp::Schema::ResultSet::User, like:
> package MyApp::Schema::Result::User;
> use Moose;
> BEGIN { extends 'DBIx::Class::ResultSet'; }
> sub confirmAndGetUser {
>     my ($self, $code) = @_;
>     return $self->find({ code => $code });
> }
> ....
> and than within your Controller: my $result =
> $c->model('DB::User')->confirmAndGetUser($code);
>
> I don't really follow you.
>
> I have generated the models with the helper script, and it generated a
> MyApp::Model::DB for me, which extends Catalyst::Model::DBIC::Schema, and
> also MyApp::Schema::Result::User, which extends DBIx::Class::Core:
>
> --------
> package MyApp::Schema::Result::User;
> use utf8;
> use Digest::MD5 qw/md5_hex/;
> use Moose;
>
> # Created by DBIx::Class::Schema::Loader
> # DO NOT MODIFY THE FIRST PART OF THIS FILE
>
> use strict;
> use warnings;
>
> use base 'DBIx::Class::Core';
> ---------
>
> I don't have a MyApp::Schema::ResultSet::User. So... now what? :)
>
>


You have to manually create that directory and the class. Have a look here:

http://search.cpan.org/~hkclark/Catalyst-Manual-5.9002/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod#Create_a_ResultSet_Class

Hth,
Dermot



More information about the Catalyst mailing list