[Dbix-class] question on syntax

Peter Sørensen maspsr at sdu.dk
Mon Feb 11 10:31:26 GMT 2008


Hi,

Using Catalyst and DBIC

Being quite new to DBIC class I really struggle with the syntax but getting closer.

I have a table named authorized_users with 3 fields: id,email,policy

a policy has many users and a user has many policies.

I would like to delete a subset of users for a given policy

The users to be deleted are in array $diff->deleted
I construct the following:

 if( @{$diff->deleted} ) {
             my $del_list;
             foreach my $val (@{$diff->deleted}) { $del_list .= "$val,";}

             my $result_set  = $c->model('DLDB::Model::CatalystModelName::AuthorizedUsers')
                 ->search({
                            -and =>  [
                                        {'policy' => $data->{policy}},
                                        {'email' => "IN($del_list)" }
                                     ]
                         } )->delete;
  }

Lets say my input is policy='policy1' and $diff->deleted contains 2 users 'user1 at xx.com, user2 at xx.com'

Outputting SQL with DBIC_TRACE set shows:


DELETE FROM authorized_users WHERE ( ( ( policy = ? ) AND ( email = ? ) ) ): 'policy1', 'IN(user1 at xx.com,user2 at xx.com )'


but this does not delete the users as expected.

I'm probably doing this wrong trying to bend DBIC class towards my way of SQL thinking.
So please clear my mind and tell me what to do or what I'm doing wrong?

regards and thanks

Peter Sorensen/University of Southern Denmark/email: maspsr at sdu.dk
 		



More information about the DBIx-Class mailing list