[CDBI] How to acess data through manytomany

[prev] [thread] [next] [Date index for 2006/01/04]

From: Bernard FRIT
Subject: [CDBI] How to acess data through manytomany
Date: 16:28 on 04 Jan 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 =3D> "Librairie::M::CDBI::Livre" );
__PACKAGE__->has_a( Id_sousrubrique =3D> "Librairie::M::CDBI::Sousrubrique"=
 );

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

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

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

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

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] How to acess data through manytomany
Bernard FRIT 16:28 on 04 Jan 2006

Re: [CDBI] How to acess data through manytomany
Perrin Harkins 16:45 on 04 Jan 2006

Re: [CDBI] How to acess data through manytomany
Bill Moseley 19:03 on 04 Jan 2006

Generated at 01:21 on 10 Jan 2006 by mariachi v0.52