[Dbix-class] $c->stash for complex/cascaded relationship bridges

Roland Philibert rphilibert at aptina.com
Mon Jan 23 14:55:30 GMT 2012


I manage to go through the database from a given primary key by doing in
the controller:

...
    my $pk = '1';
    my $t1 = $c->model('DB')->resultset('Table1')->search({ table1id =>
$pk,},  
                                                          {result_class
=> 'DBIx::Class::ResultClass::HashRefInflator',});
    
    my $rs_t2 = $c->model('DB')->resultset('Table2')->search({
'table3s.ftable1id' => $pk ,}, 
                                                          {join => {
'table3s'},
	
result_class => 'DBIx::Class::ResultClass::HashRefInflator',});
    
    while ( my $subrs = $rs_t2->next ) {
       $subrs = $c->model('DB')->resultset('Table2')->search(   {
table2id => $subrs->{table2id},  },   { } );
       push @t2 , $subrs;      
    }
    $c->stash( 	
    		t1 => [ $t1 ] , 
		rst2 => \@t2
	     );
    $c->detach($c->view("HTML"));
}



..so that's a lof of searches,
The first one is to get the info related to table1.
The second one is to get all related table2 items related to pk of
table1.
The loop create a search for each items of the second search to get
items from table4.

....keep thinking that there must be a simpler way?
Any help greatly appreciated.

Thanks


















Aptina (UK) Limited, Century Court, Millennium Way, Bracknell, Berkshire, RG12 2XT. Registered in England No. 06570543.

This e-mail and any attachments contain confidential information and are solely for the review and use of the intended recipient. If you have received this e-mail in error, please notify the sender and destroy this e-mail and any copies.




More information about the DBIx-Class mailing list