[Dbix-class] deleting from a view

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Wed Jul 6 14:01:52 GMT 2011


I have a DBIC class made up using a UNION, something like this
simplified example:

 __PACKAGE__->table('nodes');
 __PACKAGE__->result_source_instance->is_virtual(1);
 __PACKAGE__->result_source_instance->view_definition(
   "SELECT
        sp_id AS id,
        sp_status  COLLATE latin1_general_ci AS status,
        FROM sp
    UNION
    SELECT
        pr_id AS id,
        pr_status  COLLATE latin1_general_ci AS status,
        FROM pr");

It works fine but I now find I need to delete all records from the
database where status = 'obsolete'.

I've discovered that this doesn't work:

 $node_rs->search({status => 'obsolete' })->delete;

and neither does this:

 my $obs_node_rs = $node_rs->search({status => 'obsolete' });
 while (my $node = $obs_node_rs->next) {
     $node->delete;
 }

Is there some idiom that does work, or am I going to need to operate on
the individual tables separately (there are more than two, sadly)?

Cheers, Dave



More information about the DBIx-Class mailing list