[Maypole] Re: Many to Many support for Maypole (patches)
Carl Hayter
hayter@usc.edu
Sat, 26 Jun 2004 19:46:19 -0700
--Dzs2zDY0zgkG72+7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Sat, Jun 26, 2004 at 06:10:05PM -0700, steve shapero wrote:
> Hi Yuval and Maypole list--
greetings.
> I think I may only now be fully grasping what this (many to many=20
> patches, etc.) is all about. I've been trying to use a lot of has_many=
=20
> linked tables in Maypole, and the handy factory view_related macro=20
> doesn't work for them... perhaps because many to many are not fully=20
> supported, and that's why you wrote this stuff...? All I want to be=20
> able to do is show a page with all the relevant info about a product --=
=20
> which comes from all my various lookup tables... Am I better off using=20
> CDBI and making my own templates and just hacking instead of trying to=20
> get Maypole to do all this? given that i'm much more of a desperate=20
> perl hacker rather than a true programmer.
i'm not sure. you might want to check the latest Maypole v1.5, there
was a change in the related handling but i don't know if it will
help you.
i think the auto-inflating is fine for testing and such, but eventually
you want to tweak some little part so you can't use the auto stuff
anyway. for example: i had a 'url' field that i didn't want to
be turned into a hyperlink.
> for those of you on the maypole list here that haven't been following=20
> my learning curve on the CDBI list, here's my scenario:
>=20
> i have these tables (all of which have single column PKs):
> Track->has_many(artists =3D> [Trackartist =3D> 'artistid']);
> Track->has_many(genres =3D> [Trackgenre' =3D> 'genreid']);
>=20
> Trackartist->has_a(trackid =3D> Track);
> Trackartist->has_a(artistid =3D> Recordingas);
>=20
> Recordingas->has_a(personid =3D> Person);
> Recordingas->has_many(trackid =3D> [Trackartist =3D> trackid]);
>=20
> Person->has_many(aliases =3D> Recordingas);
i'm not sure i follow.
> so imagine i have data like this:
>=20
> Person: DJ Bedroom
> Recording As: Kite Flyer
> tracks by DJ Bedroom recording as Kite Flyer:
> clouds in the sky (genres: techno, rave)
> more wind blows (genres: techno, rave)
>=20
> Recording As: Reflexes
> tracks by DJ Bedroom recording as Reflexes:
> quick (genres: hiphop)
> slow (genres: hiphop, instrumentals)
>=20
> i want to display all this data -- really from the perspective of any=20
> of these items: track, genre, recording as, etc. -- and have all the=20
> other interesting data inflated in the same template.
so if i view a Person you want all of thier tracks and all of the
tracks they've done under an alias and all the albums they've
worked on and all the tracks on those albums and all the other artists
on those albums ...
that's the problem with auto-inflating stuff. it works as long as
the chain of relations ends.
but if you want, you can do it yourself in the template.
TRACKS:
[% # say person/view so object|person is the viewed thingy -%]
[% FOREACH track =3D person.tracks %]
display the [% track.name %]
[% END %]
WORKS WITH:
[% FOREACH album =3D person.albums %]
on album [% album.name %]
[% FOREACH artist =3D album.artists %]
[% IF artist.name !=3D person.name %]
display the [% artist.name %]
[% END %]
[% END %]
[% END %]
write some MACROs that display the info you want from each class
of starting object.
> i'm sort of banging my head against the wall but i feel like maypole is=
=20
> such a cool tool i'd love to use it. it may be too advanced for me=20
> alas... i'm not skilled enough to hack CDBI or Maypole code itself if=20
> that's what would be required, which i sort of am picking up on from=20
> Yuval's post. i tried setting up beerdb with the "a pub has beers on=20
> handpumps" and the sub related { "pubs" } line in BeerDB::Beer, but it=20
> didn't do anything cool. i wonder if my data is too complicated? i=20
> wonder if i should just have some gnarly flat tables and have a=20
> disgusting schema so i don't have to learn to write more code?
the latest Maypole with it's changes displays a list of Beer links
when you view a particular Brewery.
don't know if it handles multiple relations or not.
----
Carl
--Dzs2zDY0zgkG72+7
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (SunOS)
iD8DBQFA3jT6jSUgp1gR7V8RAqDTAKCQb9ybbZs69+l0eRinvhgXEXRZwQCbB5c/
CsJ8hkm7qNlowxhqq+WyU7E=
=1hRU
-----END PGP SIGNATURE-----
--Dzs2zDY0zgkG72+7--