[Dbix-class] DBIx::Class subclass and multiple tables

Oleg Pronin syber.rus at gmail.com
Wed Jun 25 16:01:56 BST 2008


In such cases i use this tactics:

1) store all the data in single table using DBIx::Class::FrozenColumns (it
allows you to store dynamic number of column in one BLOB column) and these
columns will be for you just if they were normal columns (i.e.
$obj->some_frozen_column, $obj->set_column('some_frozen_column');

2) in My::Class::User::Admin, My::CLass::User::PowerUser subclasses, add new
columns via add_frozen_columns

3) for more comfort - use DBIx::Class::DynamicSubclass - it changes the
subclass not only when you load object from DB, additionally when you change
column value on which your subclass choice depends and when you first create
a new object. (simple overriding of inflate_result - WILL NOT).


2008/6/25 Andreas Pronakis <andr3as at yahoo.com>:

> This topic might have been previously covered but i don't seem to be able
> to find the solution, so apologies in advance if it's a repeated post.
>
> Is it possible with DBIx::Class to have a class (sub-class) which
> properties are associated with two or more DB tables.
>
> A generic example would be:
>
>
> My::Class::User
> My::Class::User::Admin
> My::CLass::User::PowerUser
>
> etc.
>
> The parent class User has a table in DB (called user) that holds columns
> common to all User sub-classes, where User::Admin would also need to look=
 in
> a second DB table (called user_admin) and add the extra columns to the
> User::Admin object.  User::PowerUser would also have it's own extra table
> (call it user_poweruser).
>
> Both sub-classes will need to look into the user table to get the common
> columns and then add the extra ones from their respective tables.
>
> I can not use Database VIEWS as they are not supported in Mysql 4.0
>
> I don't mind if I have to instantiate a User object first that will then
> inflate (re-bless) itself to the appropriate sub-class (although it does
> sound a bit back to front).
>
> My main objectives are:
> 1. All this to happen with a single hit to the DB (one SQL statement)
> 2. DBIx::Class search(), find() methods will still work as normal i.e.
>    my $admin_rs =3D $schema->resultset('Admin')->find(1);
>    will return me User::Admin object with it's properties being the
> combined columns of the user and user_admin DB tables.
>
> I understand that essentially I am looking for a join between two tables,
> but i needed it on all methods, i.e. new(), find(), search(), any
> relationships etc.  Do i need to override these to get the required resul=
t?
> or DBIx::Class is not the right tool for the specific job?
>
>
> Any ideas/clues or even better code examples ;-) would be much appreciated
>
> Andreas
>
>
>
>
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080625/451=
69b95/attachment.htm


More information about the DBIx-Class mailing list