[CDBI] How to acess data through manytomany

Bernard FRIT bernard.frit at gmail.com
Wed Jan 4 16:28:41 GMT 2006


Hi,

I'm not very experienced with CDBI but I'm migrating an app from
cgi+dbi to catalyst+modperl+cdbi and experiencing some severe
drawbacks.

Here I can't figure out how to directly access data through a many to
many relationship between the "Livre" and "Sousrubrique" tables linked
together within the "Liste" table.

What I want is to get all the rows from "Livre" according to a search
like criteria on "Sousrubrique" but all I can get is an iterator. Is
there any way to populate an array
of hashes containing all the essential columns (without any explicit
programmation) ?
--
Bernard FRIT

###  Class declaration :
package Librairie::M::CDBI::Liste;
<snip>
__PACKAGE__->has_a( Id_livre => "Librairie::M::CDBI::Livre" );
__PACKAGE__->has_a( Id_sousrubrique => "Librairie::M::CDBI::Sousrubrique" );

package Librairie::M::CDBI::Sousrubrique;
<snip>
__PACKAGE__->has_many( Listes => "Librairie::M::CDBI::Liste" );
__PACKAGE__->has_many( Livres => ["Librairie::M::CDBI::Liste" => "Id_livre"] );

package Librairie::M::CDBI::Livre;
<snip>
__PACKAGE__->has_many( Listes => "Librairie::M::CDBI::Liste" );
__PACKAGE__->has_many( Sousrubriques => ["Librairie::M::CDBI::Liste"
=> "Id_sousrubrique"]

### Perl code :
    my ($sr) = Librairie::M::CDBI::Sousrubrique->search_like(libelle=>$sousr) ;
    my (@livres) = $sr->Livres ;
    $c->stash->{livres}= [ @livres ] ;

### Output
'livres' => [
                        bless( {
                                 'id_livre' => '24'
                               }, 'Librairie::M::CDBI::Livre' ),
                        bless( {
                                 'id_livre' => '15'
                               }, 'Librairie::M::CDBI::Livre' ),
                        bless( {
                                 'id_livre' => '13'
                               }, 'Librairie::M::CDBI::Livre' )
                      ],




More information about the ClassDBI mailing list