[Dbix-class] question about adding custom methods to DBIx Classes

John Napiorkowski jjn1056 at yahoo.com
Fri May 26 05:45:15 CEST 2006


Matt,

That did the trick, but I was a bit careful to try
this before since the package was marked as
experimental.  Do you thing this is starting to settle
down now or are we expecting big changes in the next
few revs of DBIx?

Thanks for such a quick reply, btw.

--john

--- Matt S Trout <dbix-class at trout.me.uk> wrote:

> John Napiorkowski wrote:
> > Hi,
> > 
> > I'm sure I'm just missing something obvious, but
> I'm
> > having trouble adding some custom methods to a
> DBIx
> > class.  I think I understand the issue but I was
> > hoping someone could help clarify for me, since I
> get
> > this to work sometime, but other times it doesnt.
> > 
> > So I have a DBIx class similar to this:
> > 
> > package myApp::Schema::members;
> > 
> > use warnings;
> > use strict;
> > 
> > use base qw/DBIx::Class/;
> > 
> > __PACKAGE__->load_components(qw/ PK::Auto Core /);
> > __PACKAGE__->table('members');
> > __PACKAGE__->add_columns(qw/ id name email /);
> > __PACKAGE__->set_primary_key(qw/ id /);
> > 
> > sub lc_name
> > {
> >    my $self  = shift @_;
> > 
> >    return lc $self->email;
> > }
> > 
> > sub id_by_email
> > {
> >    my $self  = shift @_;
> >    my $email = shift @_;
> > 
> >    return $self->find({email=>$email})->id;
> > }
> > 
> > 
> > Now, assuming that my 'email' column is specified
> as
> > unique so I can do ->find on it I can see that the
> > first function workings properly when I do (in
> > catalyst)
> > 
> > my $lc_name = $c->model("db::members")->find([any
> > valid id])->lc_name;
> > 
> > but the second function dies with a "Can't locate
> > object method "id_by_email" via package
> > "DBIx::Class::ResultSet" when I try:
> > 
> > my $id =
> $c->model("db::members")->id_by_email([any
> > valid email]);
> 
> You want a custom resultset class.
> 
>
http://search.cpan.org/~jrobinson/DBIx-Class-0.06003/lib/DBIx/Class/Manual/Cookbook.pod#Predefined_searches
> 
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Dbix-class mailing list