[Dbix-class] How to use DBIx::Class on a view

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Tue Nov 15 18:31:29 CET 2005

I would like to use DBIx::Class to access a view of a table -
specifically its a GROUP of a JOIN to aggregate a batch of per-user data
into a group summary (I'll post the actual SQL below so you can see what
I mean).

This view has no primary key, which may confuse things.

The view is certainly not picked up by DBIC::Loader - not too suprised
by that.

Can/should I wrap a ::Table based class around it, or do I need to do
other magic?

[BTW I am new to DBIx::Class - having played with CDBI a bit - I'm
finding the starting rather heavy going.  This is mostly being used with
a Catalyst app - the current Model code is very heavily based on the
example in http://dev.catalyst.perl.org/wiki/SolvedIssues#si.85 ]

The SQLite (test database - will shortly go PostgresQL) code for the
view is:-
    CREATE VIEW group_date_feature_map AS
        SELECT  date,
                count(*) AS count
        FROM user_date_feature_map
        JOIN bs_user
        ON user_date_feature_map.bs_user = bs_user.id
        GROUP BY date, bs_group, feature;

If it matters, the bs_group and feature columns are both references to
other tables.  My current database module has inflate/deflate overrides
for date fields which map them to a DateTime type.

[ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]

More information about the Dbix-class mailing list