[Dbix-class] Left join on multiple columns

John Goulah jgoulah at gmail.com
Sat May 19 03:15:03 GMT 2007


I was finally after much trial and error I was able to get something going.
I used the second method here:

http://search.cpan.org/~blblack/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.p=
od#Predefined_searches_without_writing_a_ResultSet_class

For some reason the first method didn't work for me no matter what I did.

The main thing is to load your components in the right order, at the top:

  package myDB::Sometable;

  __PACKAGE__->load_components(qw/ ResultSetManager
        PK::Auto
        Core
        /);

create a method:

  sub my_method : ResultSet {
    my ($self) =3D @_;
    return $self->search({first_name=3D> 'John'});  // or whatever
  }

and call it:
 my $userobj =3D $c->model('myDB::Sometable')->my_method();



Thanks for all who helped out, hope this helps someone else in the future.

Thanks!
John


On 5/18/07, Guillermo Roditi <groditi at gmail.com> wrote:
>
> It fails when it's in your myDB dir because DBIC tries to load it as a
> 'table' class I believe (may be wrong)
>
> # try, with a full package name
> __PACKAGE__->resultset_class(' MyApp::ResultSet::TestRes');
>
> then call your resultset the same you would have done earlier. this wont
> affect the name of your resultset, just the class it uses..
>
> On 5/18/07, John Goulah <jgoulah at gmail.com> wrote:
>
> >
> >
> > On 5/18/07, John Goulah < jgoulah at gmail.com> wrote:
> > >
> > > On 5/18/07, Guillermo Roditi <groditi at gmail.com> wrote:
> > > >
> > > > Correction, you want to add it to the ResultSet class, not the
> > > > result class! and yes there's a way.
> > > >
> > > > http://search.cpan.org/~blblack/DBIx-Class/lib/DBIx/Class/Manual/Co=
okbook.pod#Predefined_searches
> > > >
> > > > <http://search.cpan.org/%7Eblblack/DBIx-Class/lib/DBIx/Class/Manual=
/Cookbook.pod#Predefined_searches>
> > > >
> > > > http://search.cpan.org/~jrobinson/DBIx-Class-0.07999_02/lib/DBIx/Cl=
ass/Storage/DBI.pm
> > > >
> > > > <http://search.cpan.org/%7Ejrobinson/DBIx-Class-0.07999_02/lib/DBIx=
/Class/Storage/DBI.pm>
> > > >
> > > > $self->result_source->schema->storage
> > >
> > >
> > >
> > >
> > >
> > > That makes sense, but for some reason when I follow the example it
> > > wont let me start my server.  I create a directory under myDB called
> > > ResultSet, and put an object call TestRes.pm in there which contains:
> > >
> > > package myDB::ResultSet::TestRes;
> > >
> > > use strict;
> > > use warnings;
> > > use base 'DBIx::Class::ResultSet';
> > >
> > > 1;
> > >
> > >
> > > and when I try to start the catalyst server I get:
> > >
> > > Couldn't instantiate component "MyApp::Model::myDB", "Cannot load
> > > schema class 'myDB': Can't locate object method "source_name" via pac=
kage
> > > "myDB::ResultSet::TestRes" at
> > > /usr/local/share/perl/5.8.8/DBIx/Class/Schema.pm line 280.
> > > Compilation failed in require at
> > > /usr/local/share/perl/5.8.8/Catalyst/Model/DBIC/Schema.pm line 272.
> > >
> > > From searching the web it says to check the other classes mentioned in
> > > the error, all of which compile fine, and if I move the ResultSet fol=
der out
> > > of my app, things are fine.  Pulling at straws, I defined a method ca=
lled
> > > source_name, which then just leads the compiler to throw another erro=
r.
> > >
> > >
> > > Any Ideas?
> > >
> > > Thanks!
> > > John
> >
> >
> >
> >
> >
> > Also, if I move the ResultSet folder out of myDB and put it in lib, I am
> > able to start the server, but I get the error:
> >
> >  "DBIx::Class::Schema::__ANON__(): Can't find source for TestRes ......
> >
> >
> >
> >
> > I do have this in my table model schema class:
> > __PACKAGE__->resultset_class('ResultSet::TestRes');
> >
> >
> > And in my controller code I'm trying to call it like:
> > $c->model->resultset('TestRes')->get_test_result();
> >
> > which is the line the error points to.
> >
> >
> > Thanks,
> > John
> >
> >
> >
> > _______________________________________________
> > 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/
> > Searchable Archive:
> > http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> >
>
>
> _______________________________________________
> 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/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070518/9f8=
19975/attachment-0001.htm


More information about the Dbix-class mailing list