[Dbix-class] Search and Delete with Single Query

Peter Rabbitson rabbit+dbic at rabbit.us
Fri Aug 29 06:34:08 GMT 2014


On 08/28/2014 02:01 PM, Sheeju Alex wrote:
> Hi All,
>
>      Is there any way in DBIx to delete all rows from resultset in a
> single query, it looks like delete and delete_all will delete the
> resultset row by row.
>
> my $rs = $schema->resultset('User')->search({GroupId => 712});
> $rs->delete_all;
>
> If there are 100 Users in User table then the above statement will
> delete in 100 query instead is there a way to delete in single query.
>
> DELETE FROM User WHERE GroupId = 712;

This is exactly how ->delete_all is supposed to work (one by one, so 
that the business logic is invoked on per-object basis).

This is not supposed to happen with $rs->delete however. Please provide 
your version of DBIx::Class, and the true definition of the $rs (I have 
a strong suspicion you did *not* give us the actual code).




More information about the DBIx-Class mailing list