[Dbix-class] RFC: DBIx::Class::TypedView (or Is this CPAN worthy?)
Matt S Trout
dbix-class at trout.me.uk
Sat Dec 2 13:57:25 GMT 2006
Nilson Santos Figueiredo Junior wrote:
> Here we use MySQL and, unfortunately, its views are not as flexible as
> the ones available on other RDBMS (Pg, for instance) and you can't
> properly code update rules for them. MySQL can only update views whose
> rows can be directly mapped to a single table row and, even then, it's
> fairly stupid.
> In particular, MySQL can't handle views defined as a simple union of
> other tables, which is a use case somewhat present in our
> Let me exemplify the situation.
> You've got table A and table B, then you define view V as:
> 'A' AS item_type,
> A.some_field AS field
> FROM A
> 'B' AS item_type,
> B.some_other_field AS field
> FROM B;
> There's a direct mapping between each of the rows but MySQL isn't
> smart enough to handle it automatically and doesn't provide any means
> to allow the rules to be user-specified.
> So I ended up coding DBIx::Class::TypedView, which is a DBIC component
> that makes insert, update and delete operations DWIM on these tables
> provided you correctly specify the type mapping (i.e. which
> "item_type" corresponds to another given schema class) inside your
> schema class.
I -think- you've got two separate things in one class here.
First thing: inflating to different classes based on a column
Second thing: making a result source that does something odd - i.e. redirects
insertion/update/delete based on a field of the object.
OTOH, to implement the second thing means re-routing this stuff via source
then to storage which we don't currently do. So, while that's probably the
best way to implement it, this is fine for now.
If you could use TypedUnionView or some similar more descriptive name to leave
us more room for manoeuvre once the infrastructure is capable of it it'd be
More information about the Dbix-class