<font size=2 face="sans-serif">Ok, I created this file as a Resultset
and put it in a Resultset folder next to my result folder.</font>
<br>
<br><font size=2 face="sans-serif">package dbms::Schema::Result::Account;</font>
<br>
<br><font size=2 face="sans-serif">&nbsp;use base 'DBIx::Class::ResultSet';</font>
<br>
<br><font size=2 face="sans-serif">&nbsp;__PACKAGE__-&gt;load_components(qw(Helper::ResultSet::CorrelateRelationship));</font>
<br>
<br><font size=2 face="sans-serif">&nbsp;sub sub_count {</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp;my $self = shift;</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp;$self-&gt;search(undef,
{</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp;'+columns' =&gt;
{</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;num_subs
=&gt; $self-&gt;correlate('subs')-&gt;count_rs-&gt;as_query</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp;}</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp;});</font>
<br><font size=2 face="sans-serif">&nbsp;}</font>
<br>
<br><font size=2 face="sans-serif">&nbsp;1;</font>
<br>
<br><font size=2 face="sans-serif">Then I created a controller just to
see if I can get any data back from this.</font>
<br>
<br><font size=2 face="sans-serif">package dbms::Controller::subcount;</font>
<br><font size=2 face="sans-serif">use Moose;</font>
<br><font size=2 face="sans-serif">use namespace::autoclean;</font>
<br>
<br><font size=2 face="sans-serif">BEGIN {extends 'Catalyst::Controller';
}</font>
<br>
<br><font size=2 face="sans-serif">=head1 NAME</font>
<br>
<br><font size=2 face="sans-serif">dbms::Controller::subcount - Catalyst
Controller</font>
<br>
<br><font size=2 face="sans-serif">=head1 DESCRIPTION</font>
<br>
<br><font size=2 face="sans-serif">Catalyst Controller.</font>
<br>
<br><font size=2 face="sans-serif">=head1 METHODS</font>
<br>
<br><font size=2 face="sans-serif">=cut</font>
<br>
<br>
<br><font size=2 face="sans-serif">=head2 index</font>
<br>
<br><font size=2 face="sans-serif">=cut</font>
<br>
<br><font size=2 face="sans-serif">sub index :Path :Args(0) {</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; my ( $self, $c ) = @_;</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; $c-&gt;response-&gt;body('Matched
dbms::Controller::subcount in subcount.');</font>
<br><font size=2 face="sans-serif">}</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) = @_;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; my
$rows = $c-&gt;model('ORANGES::Subcount')-&gt;sub_count-&gt;all;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash(rows
=&gt; $rows);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash-&gt;{'template'}=&gt;'subcount/list';</font>
<br><font size=2 face="sans-serif">}</font>
<br>
<br><font size=2 face="sans-serif">=head1 AUTHOR</font>
<br>
<br><font size=2 face="sans-serif">root</font>
<br>
<br><font size=2 face="sans-serif">=head1 LICENSE</font>
<br>
<br><font size=2 face="sans-serif">This library is free software. You can
redistribute it and/or modify</font>
<br><font size=2 face="sans-serif">it under the same terms as Perl itself.</font>
<br>
<br><font size=2 face="sans-serif">=cut</font>
<br>
<br><font size=2 face="sans-serif">__PACKAGE__-&gt;meta-&gt;make_immutable;</font>
<br>
<br><font size=2 face="sans-serif">1;</font>
<br>
<br><font size=2 face="sans-serif">Your example shows doing this: </font>
<br>
<br><tt><font size=3>&nbsp;my $rows = $schema-&gt;resultset('Author')-&gt;with_book_count-&gt;all;</font></tt>
<br>
<br><font size=2 face="sans-serif">but it bombs out because $schema is
not declared, and I don't know what value it should hold. I have been trying
to reference it in my code above but nothing I have tried has been successful.
Please remember that I am using the Catalyst helper script to create my
model for the database, so I am coming at this from a different direction
than someone who built their own model.</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">fREW Schmidt &lt;frioux@gmail.com&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/10/2012 12:08 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 translation</font></table>
<br>
<hr noshade>
<br>
<br>
<br>
<br><font size=3>SELECT<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.server_id,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.account_code,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.server_name,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.server_type,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.os_name,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (select count(*) from server
ss, subsystem sb<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where
ss.server_id = sb.server_id<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and
ss.server_id = s.server_id) as num_subsystems<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; account a,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server s<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE a.account_id = s.account_id<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;order by a.account_code, s.server_name</font>
<br><font size=3><br>
Actually, I <b>just</b> released a helper that will do the correlated subquery
for you.&nbsp; Check it out here: </font><a href="http://search.cpan.org/~frew/DBIx-Class-Helpers-2.008000/lib/DBIx/Class/Helper/ResultSet/CorrelateRelationship.pm"><font size=3 color=blue><u>http://search.cpan.org/~frew/DBIx-Class-Helpers-2.008000/lib/DBIx/Class/Helper/ResultSet/CorrelateRelationship.pm</u></font></a><font size=3>
</font>
<br><font size=3>-- <br>
fREW Schmidt</font><font size=3 color=blue><u><br>
</u></font><a href=http://blog.afoolishmanifesto.com/><font size=3 color=blue><u>http://blog.afoolishmanifesto.com</u></font></a><tt><font size=2>_______________________________________________<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>
<br>
<br>