diff --git a/classes/Collection/Batch.class.php b/classes/Collection/Batch.class.php index 4931975e2..ccc4ac2d0 100644 --- a/classes/Collection/Batch.class.php +++ b/classes/Collection/Batch.class.php @@ -98,11 +98,12 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { $c = count($a); + $pk = $this->table->getPrimaryKeys(); $query = $this->table->getQuery()." WHERE "; - $query .= ($c > 1)?"id IN (":"id = "; + $query .= ($c > 1)?$pk[0]." IN (":$pk[0]." = "; $query .= substr(str_repeat("?, ",count($a)),0,-2); - $query .= ($c > 1)?")":""; - $query .= " ORDER BY id ASC"; + $query .= ($c > 1)?") ORDER BY ".$pk[0]." ASC":""; + $stmt = $this->table->getSession()->execute($query,array_values($a));