I have tried the same. But no change in result.
On Wednesday 15 February 2012 08:03 PM, John Romkey wrote:
On Feb 15, 2012, at 9:16 AM, tom wrote:
I have a query as follows and it is giving an extra 'undef' result while fetching the results.
my $item_cost_details_rs = $self->item_db()->resultset('ItemDetails');
my @min_cost_items = $item_cost_details_rs->search(
{},
{
join => 'item_mappings',
select => [
{ min => 'item_mappings.item_mapping_cost' },
'item_mappings.item'
],
as => [
'cost',
'item'
],
group_by => [
'item_mappings.item'
]
}
);
foreach my $row (@min_cost_items){
my %details_item = $row->get_columns();
use Data::Dumper::Simple;
print STDERR Dumper(%details_item);
}
There are only 2 results to display. But in foreach loop it s getting an undef result in first looping. 2nd and 3rd looping give me the actual result.
%details_item = (
'item' => undef,
'cost' => undef
);
Offhand I don't know why you're seeing the problem you're seeing but I'd suggest rewriting your loop using the next iterator rather than returning an array of all results:
my $min_cost_items_rs = $item_cost_details_rs->search( ... );
while( my $row = $item_cost_items_rs->next ) {
...
}
In general this is a more efficient construct - the amount of memory it uses should be independent of the size of the resultset. I suspect it will coincidentally solve your problem.
- john romkey
http://romkey.com/
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]
--

|
<<attachment: tom.vcf>>
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]