<font size=2 face="sans-serif">Yes, the helper looked very promising,
but there is little to no documentation as to what and how it does it's
thing. I tried getting it to work but to no avail as there is no indication
of how to deal with multiple things. It's example, (and I find this endemic
in DBIx docs) refers to a scalar &quot;$schema&quot; with no explanation
as to what this contains or what it should be set to. Can I substitute
&quot;$c-&gt;model('xxx::yyy') syntax for my code? No answer. where do
I put the example files it talks of? What governs the naming, is it even
important? I tried to get some answers from the author and got no response,
so I gave up.<br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Peter Rabbitson &lt;rabbit+dbic@rabbit.us&gt;</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">&quot;DBIx::Class user and developer
list&quot; &lt;dbix-class@lists.scsys.co.uk&gt;</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">05/14/2012 02:23 PM</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">Re: [Dbix-class] Query problem</font></table>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>Kenneth S Mclane wrote:<br>
&gt; I have this almost working (Ithink).<br>
&gt; <br>
&gt; sub list :Local {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; my ($self, $c, $page) = @_;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $page = $c-&gt;req-&gt;param('page') ||
1;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; my $rs = $c-&gt;model('ORANGES::Account')-&gt;search_rs(undef,
{<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; join =&gt;
{ servers =&gt; 'subs' },<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select =&gt;
[ &nbsp;{ count =&gt; 'subsystem_id' } ],<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as =&gt; [
qw/ num_subs / ],<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; group_by =&gt;
[ qw/ account_code subs.server_id <br>
&gt; server_name server_type os_name &nbsp; / ],<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rows =&gt;
15,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page =&gt;
$page,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order_by =&gt;
['account_code', 'server_name'],<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; });<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(rows =&gt; $rs);<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(pager =&gt; $rs-&gt;pager());<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash-&gt;{'template'}=&gt;'server/list';<br>
&gt; }<br>
&gt; <br>
&gt; This gives me an error:<br>
&gt; <br>
&gt; Couldn't render template &quot;server/list.tt2: undef error - DBI
Exception: <br>
&gt; DBD::DB2::db prepare_cached failed: [IBM][CLI Driver][DB2/AIX64] <br>
&gt; SQL0206N &nbsp;&quot;NUM_SUBS&quot; is not valid in the context where
it is used. <br>
&gt; &nbsp;SQLSTATE=42703<br>
&gt; [for Statement &quot;<br>
&gt; SELECT num_subs FROM (<br>
&gt; &nbsp;SELECT num_subs, ORDER__BY__1, ORDER__BY__2, ROW_NUMBER() OVER(
&nbsp;ORDER <br>
&gt; BY ORDER__BY__1, ORDER__BY__2 ) AS rno__row__index FROM (<br>
&gt; &nbsp; &nbsp;SELECT COUNT( subsystem_id ), account_code AS ORDER__BY__1,
<br>
&gt; server_name AS ORDER__BY__2 &nbsp;FROM HCDB_TEST.ACCOUNT me LEFT JOIN
<br>
&gt; HCDB_TEST.SERVER servers ON servers.account_id = me.account_id LEFT
JOIN <br>
&gt; HCDB_TEST.SUBSYSTEM subs ON subs.server_id = servers.server_id GROUP
BY <br>
&gt; account_code, subs.server_id, server_name, server_type, os_name<br>
&gt; &nbsp;) me<br>
&gt; ) me WHERE rno__row__index &gt;= ? AND rno__row__index &lt;= ?<br>
&gt; <br>
<br>
I think this is the result of a bug that I am pretty sure is<br>
fixed in the last CPAN version. What version are you using?<br>
<br>
In any case as you correctly noticed you want a subquery not a<br>
bunch of crazy group bys.<br>
<br>
&gt; But the SQL looks like it is getting closer to what I need:<br>
&gt; <br>
&gt; SELECT<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.server_id, &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a.account_code,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.server_name,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.server_type,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.os_name,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(select count(*) from
server ss, subsserystem sb<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
where ss.server_id = sb.server_id<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
and ss.server_id = s.server_id) as num_subsystems &nbsp; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;account a,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;server s<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and a.account_id = s.account_id<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order by a.account_code,
s.server_name&quot;<br>
&gt; <br>
<br>
Correct. Then you were told that this is a thing that only became<br>
*easy* recently. You were given links to the helper component<br>
implementing precisely what you need. If your development model<br>
prevents you from using such components you will have a *very* hard<br>
time working with DBIx::Class, Catalyst and many other current CPAN<br>
libraries.<br>
<br>
&gt; I have exhausted all the docs I can find <br>
<br>
I replied with the actual link to an email while I was typing up this<br>
reply. I would still like to make a point that if you continue to try<br>
to model specific SQL queries using DBIC, you will have a very very<br>
hard time going forward. This is not entirely a deficiency of DBIC,<br>
mostly it is the complexity of the task of *reliably* abstracting all<br>
the vagaries of SQL into a coherent, incrementally buildable API. So<br>
start small by getting back the data you want, and worrying about the<br>
resulting queries on a later stage, when you have an actual feel of<br>
the tools you are using. Expecting to jump into a set of libraries and<br>
be able to make them to behave *exactly* like you want is only going<br>
to set your stage for many bitter disappointments.<br>
<br>
Hope this helps.<br>
<br>
Cheers!<br>
<br>
_______________________________________________<br>
List: </font></tt><a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class"><tt><font size=2>http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</font></tt></a><tt><font size=2><br>
IRC: irc.perl.org#dbix-class<br>
SVN: </font></tt><a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/"><tt><font size=2>http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</font></tt></a><tt><font size=2><br>
Searchable Archive: </font></tt><a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk"><tt><font size=2>http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</font></tt></a><tt><font size=2><br>
<br>
</font></tt>
<br>
<br>