Yes. It has has_many . But left join is having no issue.
I have tried the query obtained from console in sqlyog as well as in command prompt. Their i am getting the correct result.

The query getting from console is:
SELECT MIN( item_mappings.item_mapping_cost ), item_mappings.item
FROM item_details me LEFT JOIN item_mapping item_mappings ON item_mappings.item_details_id = me.item_details_id GROUP BY item_mappings.item

The contradictory part is that the same code in another file is giving me the actual result.

On Wednesday 15 February 2012 08:07 PM, Peter Rabbitson wrote:
On Wed, Feb 15, 2012 at 07:46:21PM +0530, 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
                );
    
How do you know there are 2 results to display? Did you run the actual query
as seen in DBIC_TRACE=1 through your console? Given the above construct I am
pretty sure item_mappings is a has_many, which means it is a left join, which
means you have several all nulls "rows" on the right side, which are
collapsed by the group to a single null/null/null... result, and returned to
you.

All speculation of course, the actual SQL will make it clearer.


_______________________________________________
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]

Reply via email to