[Dbix-class] Search and Delete with Single Query
Sheeju Alex
sheejuec7 at gmail.com
Fri Aug 29 18:41:27 GMT 2014
I tried ->delete and ->delete_all both operation was deleting one by one.
The version of DBIx::Class is 0.08250
You guessed right :) I had changed the table name but the code is no
different, here is the code and schema definition of $rs
$schema->resultset('AlertParameterValue')->search({ProfileId =>
712})->delete;
Schema Class is below and I don't have cascade relationship or is_deferable
use utf8;
package PAMS::WWW::Schema::Result::AlertParameterValue;
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
__PACKAGE__->table("AlertParameterValue");
__PACKAGE__->add_columns(
"Id",
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
sequence => "\"AlertParameterValue_Id_seq\"",
},
"ProfileId",
{data_type => "integer", is_nullable => 1},
"Value",
{data_type => "varchar", is_nullable => 0, size => 255},
);
__PACKAGE__->set_primary_key("Id");
# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-06-19 16:08:39
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ykWXuRi/+hlXQIwEwVakfQ
__PACKAGE__->belongs_to(
Profile => 'PAMS::WWW::Schema::Result::AlertProfile',
{'foreign.Id' => 'self.ProfileId'}
);
# PgLog Settings goes here
__PACKAGE__->load_components(qw/PgLog/);
# You can replace this text with custom code or comments, and it will be
preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
Best Regards,
Sheeju Alex
On Fri, Aug 29, 2014 at 12:04 PM, Peter Rabbitson <rabbit+dbic at rabbit.us>
wrote:
> 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).
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/
> dbix-class at lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20140830/d95d7b52/attachment.htm>
More information about the DBIx-Class
mailing list