[Dbix-class] Problem retrieving data

Anthony Gardner cyclewood_ltd at yahoo.co.uk
Mon May 21 13:25:18 GMT 2007


This is probably bread 'n butter to you but ........

I have the following table relationships .....

groups ---< categories ---< subcategories ----< products

for a group, I want to retrieve all of its categories, the catgeories' subcats etc.

i have this .........

## switch between list and rs context
my $group_rs =
my @group = $schema->resultset('ProductGroup')->search( { 'me.id' => 18 }, 
                                                           { select => [ 'me.name', 'categories.name', 'subcategories.name', 'products.name'],
                                                                as => [ qw|group_name category_name subcategory_name product_name|],
                                                               join => { categories => { subcategories => 'products' }}
                                                           });

....... which I think is right but I can;t get at all the rows from the returned resultset. If I return a list, it works. $group_rs->next() in a loop just returns the first row.

## this works in ist context
foreach my $group ( @groups ) {
    my $group_name  = $group->get_column('group_name');
    my $cat_name    = $group->get_column('category_name');
    my $subcat_name = $group->get_column('subcategory_name');
    my $prod_name   = $group->get_column('product_name');
    print "$group $group_name => $cat_name => $subcat_name => $prod_name\n";    
}

=pod    
 ## this doesn't work for all rows context                                                      
foreach my $group ( $group_rs->next() ) {
    my $group_name  = $group->get_column('group_name');
    my $cat_name    = $group->get_column('category_name');
    my $subcat_name = $group->get_column('subcategory_name');
    my $prod_name   = $group->get_column('product_name');
    print "$group $group_name => $cat_name => $subcat_name => $prod_name\n";
}
=cut

I'd like to use the rs copntext and print something like .........

group1
  cat1
     subcat1
         prod1
          prod2
         prod3
      subcat2
        prod4
      subcat3
         prod5
  cat2
     subcat4
        ..... etc. etc.

Any tips would be greatly/warmly appreciated.

-Ants

 		
---------------------------------
 Yahoo! Messenger - with free PC-PC calling and photo sharing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070521/f5d489cd/attachment.htm


More information about the Dbix-class mailing list