arc_of_descent has asked for the wisdom of the Perl Monks concerning the following question:
and the two SQL queries which are generated:# search for im_network @search_msgs = $schema->resultset('Message')->search( { 'from_user.im_network' => 'Yahoo', }, { join => 'from_user' }, ); ok (scalar @search_msgs == 2, 'join message to user'); # search for receiving_user @search_msgs = $schema->resultset('Message')->search( { 'user.im_username' => 'linux_rohan', }, { join => { conversation => { 'users' => 'user' } } }, ); ok (scalar @search_msgs == 2, 'join message to users');
SELECT me.id, me.conversation, me.from_user, me.message, me.timestamp +FROM message me JOIN user from_user ON ( from_user.id = me.from_user + ) WHERE ( from_user.im_network = ? ): 'Yahoo' SELECT me.id, me.conversation, me.from_user, me.message, me.timestamp +FROM message me JOIN conversation conversation ON ( conversation.id += me.conversation ) LEFT JOIN conversation_user users ON ( users.conv +ersation = conversation.id ) LEFT JOIN user user ON ( user.id = users +.user ) WHERE ( user.im_username = ? ): 'linux_rohan'
The above code works great. Apologies for not divulging any pre information. I basically need a query which combines the above two joins.
I tried passing an arrayref to join, like this,
{ join => [ conversation => { 'users' => 'user' }, 'from_user', ]};
but this does not work and says "No such relationship users". I'm not sure I have the correct syntax.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBIx::Class - A question on using joins
by arc_of_descent (Hermit) on Sep 11, 2007 at 19:48 UTC |