views:

72

answers:

1

I'm struggling with doing this, I want to basically do a database deleteAll where one field is equal to something and another field must NOT be equal to something.. its for deleting duplicate rows so I want to delete all but one row.. the way I tried below isn't working, I Would appreciate any advice:

 $conditions = array (
  "Prox.proxy" => $currentproxytocheck,
  "AND" => array (
   "NOT" => array (
    "Prox.proxyid" => $currentproxyid
   )
  )
 );

$this->Prox->deleteAll(array( 'conditions' => $conditions)); 

EDIT:

The printout of my $conditions array is:

Array
(
    [Prox.proxy] => 62.58.179.2:80
    [AND] => Array
        (
            [NOT] => Array
                (
                    [Prox.proxyid] => 36829
                )

        )

)

Error from CAkephp:

Notice (8): Array to string conversion [CORE/cake/libs/model/datasources/dbo_source.php, line 2193]
Warning (512): SQL Error: 1054: Unknown column 'conditions' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 673]   
A: 

The syntax for deleteAll is different from find

deleteAll(mixed $conditions, $cascade = true, $callbacks = false)

Use

$this->Prox->deleteAll($conditions); 

And your array could be built like so:

$conditions = array (
    "Prox.proxy" => $currentproxytocheck,
    "Prox.proxyid <>" => $currentproxyid
);

Which is the same thing, but more readable.

quantumSoup
There are definitely records like that, I've checked this and tested it directly without using variables (using specific values that I know are correct).. I'm trying to do it the cakephp way, not using direct mysql calls, so thats the issue more than anything as there is sparse documentation on the deleteall method
Rick
@Rick So is your array being built correctly?
quantumSoup
as far as I can tell.. I edited my OP with the print of the array
Rick
I added the error I get to OP too, should have put that in initially
Rick
@Rick See edited post
quantumSoup
Thanks, will try that
Rick
=) thanks very much, that solved it
Rick