[CDBI] Adding metadata to objects

Bill Moseley moseley at hank.org
Tue Sep 27 20:42:43 BST 2005

Does CDBI provide a way to add meta data to object instances?

I want to generate a list of CDs, say limited to a given genre.  So
using Catalyst in this example, in the controller I might say:

    $c->stash->{items} = Music::CD->search( { genre => 'Rock' } );

Now in the template I want to list the CDs, and also list the tracks
on the CD:

    WHILE (item = items.next);
        "Title = "; item.title;

        # list tracks
        tracks = item.tracks;
        WHILE (track = tracks.next);
            "* Track "; track.title;

Here's the question:  assume that the CD has an overall genre, but
also each *individual* track also has a genre and I only want to list
tracks that have a genre that matches the genre used for the original
query on the CDs.

So above the "tracks = item.tracks" would only return tracks that also
have genre = 'Rock'.

So, what I want to do is add "genre => 'Rock'" as meta data to each CD
instance, and then when calling "tracks" on a CD have that method use
that genre in the query.

Bill Moseley
moseley at hank.org

More information about the ClassDBI mailing list