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);
Cheers,
Dimi
On Thu, Oct 27, 2011 at 5:24 AM, Csongor Fagyal <[email protected]>wrote:
> Hi All,
>
> Please excuse me if I ask lame questions. There's just so much
> documentation lying around that it's hard to find what I am looking for.
>
> --------------
>
> Basically I have a (generated) DBIx::... model, and I would like to fetch
> another instance from it. (What I am trying to achieve is to make the model
> verify a confirmation code for a user, and return the corresponding user
> object if the code is right.)
>
> So... it looks like this:
>
> # somewhere in a controller:
>
> my $result = $c->model('DB::User')->new_**result({})->confirmAndGetUser(**
> $c,$code);
>
> # Then in User.pm:
>
> package MyApp::Schema::Result::User;
> use utf8;
> # Created by DBIx::Class::Schema::Loader
> # DO NOT MODIFY THE FIRST PART OF THIS FILE
> # ... etc ....
>
> sub confirmAndGetUser {
> my ($self,$c,$code) = @_;
>
> # ... generate $uid from $code, etc...
>
> my $user = $c->model("DB::User")->find($**uid);
> $user || return 'Wrong verification code.";
>
> # ... etc ...
>
> return $user;
> }
>
>
> My problem is that I pass $c to the model, which looks like a bad idea in
> general. (It's ugly at least.) But how can I do a find(...) otherwise? Can I
> do something like
> $self->something->**somethingelse->andwhatnoat('**User')->find(
> ... ) ?
>
> As the matter of fact, the whole thing would look much better to me as a
> class method instead of an instance method. Something like this:
>
> my $user = MyApp::Schema::Result::User->**confirmAndGetUser($code);
>
> Is that doable? (Doesn't feel like it...)
>
>
> BTW, "you should do this differently, like this: ..." is also an acceptable
> answer :) [ Maybe what I am trying to do should go somewhere else... not in
> the controller, not in the model, but... ? ]
>
> Also, if this is a FAQ item, please point me to that FAQ :)
>
>
> Thank you,
> - Fagzal
>
>
> ______________________________**_________________
> List: [email protected]
> Listinfo:
> http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/catalyst<http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>
> Searchable archive: http://www.mail-archive.com/**
> [email protected]/<http://www.mail-archive.com/[email protected]/>
> Dev site: http://dev.catalyst.perl.org/
>
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/