Matija Grabnar wrote:
> I've been trying to follow the example made in the cookbook, but for some
> reason, the "as"=> part doesn't seem
> to be working:
>
> my $qs=$schema->resultset('Schema::Msgs')->search({},
> {select => [ 'quar_type',{ count => '*' } ],
> join => [ qw/quarantined/],
> as => [ qw/quar_type qcount/],
> group_by => [ qw/quar_type/],
> });
>
> Here is the actualy query that gets executed:
>
> SELECT quar_type, COUNT( * ) FROM msgs me LEFT JOIN quarantine quarantined ON
> ( quarantined.mail_id = me.mail_id ) GROUP BY quar_type
>
> The problem is that since the as part doesn't execute, I can't do an order_by
> /qcount/, and what's even
> worse, I can't get to the count!
You *can* get to the count. DBIC will populate a 'qcount' column in the
inflated object, so
$obj->get_column('qcount')
will work fine.
As noted in the ResultSet docs
as
Arguments: (arrayref)
Indicates column names for object inflation. This is used
in conjunction with "select", usually when "select" conĀ
tains one or more function or stored procedure names:
the 'as' attribute does *not* translate to SQL. It's for the DBIC stuff only.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/