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
applications.

Let me exemplify the situation.
You've got table A and table B, then you define view V as:

 SELECT
    'A' AS item_type,
    A.some_field AS field
 FROM A
 UNION
 SELECT
    '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 appreciated.

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to