[CDBI] Adding metadata to objects

Bill Moseley moseley at hank.org
Tue Sep 27 21:42:41 BST 2005


On Tue, Sep 27, 2005 at 04:17:12PM -0400, Kingsley Kerce wrote:
> Bill Moseley writes:
>  > 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
> 
> Bill -- Is genre a column in the CD and track tables?  If yes then
> just refer to item.genre (the CD's genre) in your template, discarding
> tracks whose genre doesn't match.

The Music example doesn't exactly fit my real database.  I was just
using it as an example.  I have a number of parameters that I need to
pass, and I can't test them based on existing columns.

The question is more about how to add metadata to an instance.

The real situation is this:

__PACKAGE__->set_sql('workshop_summary', <<SQL);
    SELECT id, name, short_description, scheduled_message, no_scheduled_message
    FROM workshop
    WHERE id IN (
        SELECT DISTINCT workshop FROM class
        WHERE
            register_cutoff_time >= now()
            AND review_mode IS NOT TRUE
            AND workshop_group = 1
    UNION
        SELECT id FROM workshop
        WHERE
            start_display_time IS NOT NULL
            AND start_display_time < now()
            AND (stop_display_time IS NULL or stop_display_time >= now())
            AND review_mode IS NOT TRUE
            AND workshop_group = 1
    )
    ORDER by name
SQL

Where the time "now()", review_mode, workshop_group (and a few others)
are set at run-time.  Then those same parameters used above need to be
passed in another method that fetches specific classes for each
workshop id returned above:

__PACKAGE__->set_sql('scheduled_classes', <<SQL);
    SELECT id, class_time, location
    FROM class
    WHERE 
        workshop = ?
        AND register_cutoff_time >= now()
        AND review_mode IS NOT TRUE
        AND workshop_group = 1
    ORDER by class_time
SQL

So, currently I'm storing all the parameters in the catalyst stash and
passing those parameters when calling "scheduled_classes".  But it
would be nice to store the parameters as metadata in each instance
form the first select making them available for the second select.

In other words:

    item.scheduled_classes

would then pass in the parameters used to select the "item" in the
first place.

Make sense?


-- 
Bill Moseley
moseley at hank.org





More information about the ClassDBI mailing list