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::Result*Set*::User. So... now what? :)
Thanks,
- Fagzal
Cheers,
Dimi
On Thu, Oct 27, 2011 at 5:24 AM, Csongor Fagyal
<[email protected] <mailto:[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] <mailto:[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/
_______________________________________________
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/
_______________________________________________
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/