<font size=2 face="sans-serif">I am trying to convert my database views
into actual queries. </font>
<br><font size=2 face="sans-serif">My view code:</font>
<br>
<br><font size=2 face="sans-serif">sub list :Local {</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; my
($self, $c, $page) = @_;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $page
= $c-&gt;req-&gt;param('page') || 1;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; my
$rs = $c-&gt;model('ORANGES::Contacts')-&gt;search_rs(undef, { </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; order_by =&gt; 'contact_name',</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; rows =&gt; 15,</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; page =&gt; $page,</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(contacts
=&gt; $rs);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(pager
=&gt; $rs-&gt;pager());</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash-&gt;{'template'}=&gt;'contacts/list';</font>
<br><font size=2 face="sans-serif">}</font>
<br>
<br><font size=2 face="sans-serif">This results in a paged result set of
60 pages of 15 record each. Resultant sql:</font>
<br>
<br><font size=2 face="sans-serif">SELECT contact_id, contact_name, contact_email,
contact_role, team_flag, department_id, department_code FROM (</font>
<br><font size=2 face="sans-serif">&nbsp; SELECT contact_id, contact_name,
contact_email, contact_role, team_flag, department_id, department_code,
ROW_NUMBER() OVER( &nbsp;ORDER BY contact_name ) AS rno__row__index FROM
(</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; SELECT me.contact_id,
me.contact_name, me.contact_email, me.contact_role, me.team_flag, me.department_id,
me.department_code &nbsp;FROM HCDB_TEST.CONTACTS me</font>
<br><font size=2 face="sans-serif">&nbsp; ) me</font>
<br><font size=2 face="sans-serif">) me WHERE rno__row__index &gt;= ? AND
rno__row__index &lt;= ?</font>
<br>
<br><font size=2 face="sans-serif">: '1', '15'</font>
<br><font size=2 face="sans-serif">SELECT COUNT( * ) FROM HCDB_TEST.CONTACTS
me:</font>
<br>
<br><font size=2 face="sans-serif">My revised code, it's almost working:</font>
<br>
<br><font size=2 face="sans-serif">sub list1 :Local {</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; my
($self, $c, $page) = @_;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $page
= $c-&gt;req-&gt;param('page') || 1;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; my
$rs = $c-&gt;model('ORANGES::Contact')-&gt;search_rs(undef, {</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; join =&gt; 'department_id',</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; order_by =&gt; 'contact_name',</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; prefetch =&gt; 'department_id',</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; rows =&gt; 15,</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; page =&gt; $page,</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; });</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(contacts
=&gt; $rs);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(pager
=&gt; $rs-&gt;pager());</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash-&gt;{'template'}=&gt;'contacts/list';</font>
<br><font size=2 face="sans-serif">}</font>
<br>
<br><font size=2 face="sans-serif">This results in only 5 records and I
am not sure why. Resultant SQL:</font>
<br>
<br><font size=2 face="sans-serif">SELECT contact_id, contact_name, contact_email,
contact_role, team_flag, department_id, department_id__department_id, department_id__department_code,
department_id__department_pid, department_id__manager_id FROM (</font>
<br><font size=2 face="sans-serif">&nbsp; SELECT contact_id, contact_name,
contact_email, contact_role, team_flag, department_id, department_id__department_id,
department_id__department_code, department_id__department_pid, department_id__manager_id,
ROW_NUMBER() OVER( &nbsp;ORDER BY contact_name ) AS rno__row__index FROM
(</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; SELECT me.contact_id,
me.contact_name, me.contact_email, me.contact_role, me.team_flag, me.department_id,
department_id.department_id AS department_id__department_id, department_id.department_code
AS department_id__department_code, department_id.department_pid AS department_id__department_pid,
department_id.manager_id AS department_id__manager_id &nbsp;FROM HCDB_TEST.CONTACT
me &nbsp;JOIN HCDB_TEST.DEPARTMENT department_id ON department_id.department_id
= me.department_id</font>
<br><font size=2 face="sans-serif">&nbsp; ) me</font>
<br><font size=2 face="sans-serif">) me WHERE rno__row__index &gt;= ? AND
rno__row__index &lt;= ?</font>
<br>
<br><font size=2 face="sans-serif">: '1', '15'</font>
<br><font size=2 face="sans-serif">SELECT COUNT( * ) FROM HCDB_TEST.CONTACT
me &nbsp;JOIN HCDB_TEST.DEPARTMENT department_id ON department_id.department_id
= me.department_id: </font>
<br>
<br><font size=2 face="sans-serif">It seems that my code is doing funny
things with the join, I had to modify my template code to get it to display
the department_code by changing it from [% contact.department_code %] to
[% contact.department_id.department_code %].</font>
<br>
<br><font size=2 face="sans-serif">Some help with where I went wrong would
be appreciated.<br>
</font>
<br><font size=2 face="Arial">Regards</font>
<br>
<br>