[Dbix-class] Problems getting prefetch to work..

Tim Watson tiwatson at gmail.com
Sat Jun 24 21:53:05 CEST 2006


>>The sessionid in the where clause is not attributed to any table...

Actually I was wrong on that... add a LEFT before the JOIN in the sql
statement and it works fine.

-tim

On 6/24/06, Tim Watson <tiwatson at gmail.com> wrote:
> >>
> __PACKAGE__->belongs_to(username => 'Db::Schema::User');
>
> so try "username" since that's the name of the relationship.
> <<
>
> Thats what I had in my original question.. It gives a mysql error...
>
> SELECT me.sessionid, me.username, username.username, username.password
> FROM session me  JOIN user username ON ( username.username =
> me.username ) WHERE ( sessionid = ? )' (`123456')
>
> The sessionid in the where clause is not attributed to any table...
>
> Thanks for all the replies though.. This is a very cool module.
> --
> my $rs = $dbh->resultset('Session')->search({ 'session.sessionid' =>
> '123456' } ,{ prefetch => 'username' });
> my $session = $rs->next;
> print "s " . $session->sessionid . "\n";
>
> (prefetching on anything but username gives me a relationship error)
> --
>
>
> On 6/24/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> > Tim Watson wrote:
> > > On 6/24/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> > >> Tim Watson wrote:
> > >>> I think I was going about this a little reverse...
> > >>>
> > >>> This works...
> > >>>
> > >>>     my $rs = $dbh->resultset('User')->search({ 'sessionid' => '123456'
> > >>> } ,{ prefetch => 'user_session' });
> > >>>
> > >>> But I am unable to figure out how to access anything else in that
> > >>> session row... since I am returned a user object by $rs->next;
> > >>>
> > >>> I would like to be able to get a session obect and the user object
> > >>> from that one line..
> > >> Oh, actually you're going to end up with a resultset of session objects
> > that
> > >> way. What you want is
> > >>
> > >> my $rs = $dbh->resultset('Session')->search({ 'sessionid' => '123456'
> },
> > {
> > >> prefetch => 'user' });
> > >>
> > >> then $rs->next will return a $session object with $session->user
> already
> > >> populated with the appropriate user object
> > >>
> > >
> > > That doesn't work... it gives me the relationship error...
> > >
> > > DBIx::Class::ResultSet::search(): No such relationship user
> >
> > __PACKAGE__->belongs_to(username => 'Db::Schema::User');
> >
> > so try "username" since that's the name of the relationship.
> >
> > --
> >       Matt S Trout       Offering custom development, consultancy and
> > support
> >    Technical Director    contracts for Catalyst, DBIx::Class and BAST.
> > Contact
> > Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more
> information
> >
> > + Help us build a better perl ORM:
> http://dbix-class.shadowcatsystems.co.uk/
> > +
> >
> > _______________________________________________
> > 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/
> >
>
>
> --
> Tim Watson
> Solution Scripts
>


-- 
Tim Watson
Solution Scripts



More information about the Dbix-class mailing list