<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title></title>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
body {
  margin: 5px 5px 5px 5px;
  background-color: #ffffff;
}
/* ========== Text Styles ========== */
hr { color: #000000}
body, table /* Normal text */
{
 font-size: 9pt;
 font-family: 'Courier New';
 font-style: normal;
 font-weight: normal;
 color: #000000;
 text-decoration: none;
}
span.rvts1 /* Heading */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-weight: bold;
 color: #0000ff;
}
span.rvts2 /* Subheading */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-weight: bold;
 color: #000080;
}
span.rvts3 /* Keywords */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-style: italic;
 color: #800000;
}
a.rvts4, span.rvts4 /* Jump 1 */
{
 font-size: 10pt;
 font-family: 'Arial';
 color: #008000;
 text-decoration: underline;
}
a.rvts5, span.rvts5 /* Jump 2 */
{
 font-size: 10pt;
 font-family: 'Arial';
 color: #008000;
 text-decoration: underline;
}
span.rvts6
{
 font-size: 11pt;
 font-family: 'tahoma';
 font-weight: bold;
 color: #ffffff;
 background-color: #0000ff;
}
span.rvts7
{
 font-size: 11pt;
 font-family: 'tahoma';
}
span.rvts8
{
 font-size: 11pt;
}
span.rvts9
{
 font-size: 8pt;
 font-family: 'arial';
 font-style: italic;
 color: #c0c0c0;
}
a.rvts10, span.rvts10
{
 font-size: 8pt;
 font-family: 'arial';
 color: #0000ff;
 text-decoration: underline;
}
/* ========== Para Styles ========== */
p,ul,ol /* Paragraph Style */
{
 text-align: left;
 text-indent: 0px;
 padding: 0px 0px 0px 0px;
 margin: 0px 0px 0px 0px;
}
.rvps1 /* Centered */
{
 text-align: center;
}
--></style>
</head>
<body>

<p>Здравствуйте, Angel.</p>
<p><br></p>
<p>Вы писали 8 декабря 2007 г., 18:36:55:</p>
<p><br></p>
<div><table border=0 cellpadding=1 cellspacing=2>
<tr valign=top>
<td width=12 style="background-color: #0000ff;">
<p><span class=rvts6>&gt;</span></p>
</td>
<td width=857 style="background-color: #ffffff;">
<p><span class=rvts7>Hi, All. Im new in DBIx::Class and this is my first question here :)</span></p>
<p><span class=rvts7>I write catalyst app and use dbic for 3 tables (males,females,family) &nbsp;with has_many and may_to_many. All works, but there are too many requests to my database when i use this:&nbsp;</span></p>
<p><span class=rvts8>&nbsp;my $rs = $c-&gt;model('AppModelDB::ClientMale')-&gt;search();</span></p>
<p><span class=rvts8>while (my $line = $rs-&gt;next) {</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; push @{$families},[ $line-&gt;client_family-&gt;first-&gt;id,</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;make_family(</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$line-&gt;first_n,&nbsp;</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$line-&gt;family_n,</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$line-&gt;client_female-&gt;first-&gt;first_n,</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$line-&gt;client_female-&gt;first-&gt;family_n&nbsp;</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;city</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;zip_code</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;municipality&nbsp;</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;street</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;public_place_type</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,$line-&gt;client_family-&gt;first-&gt;public_place_name</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ];</span></p>
<p><span class=rvts8>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p><span class=rvts8>}</span></p>
<p><span class=rvts8>$c-&gt;stash-&gt;{families} = $families;</span></p>
<p><br></p>
<p><span class=rvts7>I wrote "export DBIC_TRACE=1" for debug and saw alot of screens with SELECT requests to MySQL. Plese help me to optimize the code. Every single table has around 190 lines.&nbsp;</span></p>
<p><span class=rvts7>Thank you</span></p>
</td>
</tr>
</table>
</div>
<p><br></p>
<p><br></p>
<p>Use 'join' or 'prefetch' attribute for search. Also see the Cookbook http://search.cpan.org/~ash/DBIx-Class-0.08008/lib/DBIx/Class/Manual/Cookbook.pod#JOINS_AND_PREFETCHING</p>
<p><br></p>
<p><span class=rvts9>--&nbsp;</span></p>
<p><span class=rvts9>С уважением,</span></p>
<p><span class=rvts9>&nbsp;dreel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a class=rvts10 href="mailto:dreel@bk.ru">mailto:dreel@bk.ru</a></p>

</body></html>