You're dead on Will - that makes it work perfectly.<br><br>Thanks for your help.<br><br><div><span class="gmail_quote">On 4/3/06, <b class="gmail_sendername">Will Hawes</b> &lt;<a href="mailto:info@whawes.co.uk">info@whawes.co.uk
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">luke saunders wrote:<br>&gt; Is this the expected behaviour of prefetch? Apologies for not replacing
<br>&gt; all the names with 'foo', 'bar' etc.<br>&gt;<br>&gt; Receptor has a 'many to many' relationship with Ligand, with<br>&gt; 'natural_ligands_map' being the bridging relationship.<br>&gt;<br>&gt; I want to preform a search on Receptor which prefetches all the Ligand
<br>&gt; rows. So I do the following:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; my $rs = $c-&gt;config-&gt;{schema}-&gt;resultset('Receptor')-&gt;search<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ({class4 =&gt; 'Orphan'},<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{prefetch =&gt; {natural_ligands_map =&gt; 'ligand'}});
<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; my $count = $rs-&gt;count;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; # $count is 0 here<br>&gt;<br>&gt; The search returned no results despite there being 60 Receptor rows<br>&gt; which have a class4 of 'Orphan'. The reason for this is that these
<br>&gt; receptors don't have any Ligands. Proved by the following :<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; my $rs = $c-&gt;config-&gt;{schema}-&gt;resultset('Receptor')-&gt;search<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ({class4 =&gt; 'Orphan'});<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; my $count = $rs-&gt;count;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; # $count is 60 here<br>&gt;<br>&gt; this returns 60 receptors as expected.<br>&gt;<br>&gt; Now, I want the Receptor rows even if they don't have any Ligands but<br>&gt; that doesn't appear to be possible. Is this a bug or is it the expected
<br>&gt; behaviour? If it's a bug I'll knock up a test case for y'all.<br>&gt;<br>&gt; Obviously not doing the prefetch solves the problem but in this case<br>&gt; that's much too expensive.<br>&gt;<br>&gt; Thanks,<br>&gt; Luke.
<br>&gt;<br>&gt; Resulting debug SQL from first search for reference (I replaced the<br>&gt; column names with * to save space):<br>&gt; SELECT me.*, natural_ligands_map.*, ligand.* FROM receptors me LEFT JOIN<br>&gt; natural_ligands_2_receptors natural_ligands_map ON (
<br>&gt; natural_ligands_map.gpcrid = me.gpcrid )&nbsp;&nbsp;JOIN natural_ligands ligand ON<br>&gt; ( ligand.ligid = natural_ligands_map.ligid ) WHERE ( ( ( class4 = ? ) )<br>&gt; ) ORDER BY natural_ligands_map.gpcrid: `Orphan'<br>
<br><br>If I've read that correctly, you need the natural_ligands_map to<br>generate LEFT JOIN rather than JOIN to get the desired behaviour.<br><br>That can be specified in your model class for the natural_ligands_map<br>
table. I'm not 100% on the syntax, but I think it should be something<br>like this:<br><br>package Your::NaturalLigandsMap::Class';<br>...<br>__PACKAGE__-&gt;has_many( 'natural_ligands' =&gt;<br>'Your::NaturalLigands::Class', 'ligid', { join_type =&gt; 'left' } );
<br><br>_______________________________________________<br>List: <a href="http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class">http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class</a><br>Wiki: <a href="http://dbix-class.shadowcatsystems.co.uk/">
http://dbix-class.shadowcatsystems.co.uk/</a><br>IRC: irc.perl.org#dbix-class<br>SVN: <a href="http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/">http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/</a><br></blockquote>
</div><br>