[Dbix-class] deleting from a view
Darren Duncan
darren at darrenduncan.net
Tue Jul 12 21:38:14 GMT 2011
Peter Edwards wrote:
> On 6 July 2011 15:01, Dave Howorth <dhoworth at mrc-lmb.cam.ac.uk> wrote:
>
> I have a DBIC class made up using a UNION, something like this
> __PACKAGE__->result_source_instance->is_virtual(1);
> __PACKAGE__->result_source_instance->view_definition(
> "SELECT
> sp_id AS id,
>
> ...
>
> I've discovered that this doesn't work:
>
> $node_rs->search({status => 'obsolete' })->delete;
>
> I thought you couldn't Delete through a View in most databases?
You should be able to do any of insert/update/delete through a View where
resolving that is logically possible; being able to treat views as ordinary
tables in all respects where possible is part of what makes a relational database.
And deletes through a union are a very simple case that should be easily
supported; you just do the same delete on all of the tables in the union.
Some DBMSs do natively support writing to views, and for those that don't, DBIC
should be able to implement it, especially for simpler cases like deletes on
simple union views. If DBIC doesn't do this, its just a matter of tuits.
-- Darren Duncan
More information about the DBIx-Class
mailing list