Doctrine Query Builder: how to build a query which contains "ON DUPLICATE KEY UPDATE"

Viewed 382

Is this possible to implement multiple insert query with on duplicate key update with Doctrine Query Builder? Because I don't see any methods of Query Builder that can help writing such a query.

I have list of objects, I need to update their status fields, instead of writing many update queries I want to solve this by writing just single one "insert into" query.

This is how I used to solve this before installing Doctrine into my project:

$query = "INSERT INTO BRO_campaign(`id`, `name`) ";

for ($this->listOfRunningCampaigns->rewind(); $this->listOfRunningCampaigns->valid(); $this->listOfRunningCampaigns->next())
{
      $current = $this->listOfRunningCampaigns->current();
      $query .= " VALUES(" . $current->getId() . ", '" . $current->getName() . "'),";
}

// Deleting comma in the end of line
$query = substr($query, 0, -1);
$query .= " ON DUPLICATE KEY UPDATE BRO_campaign.`status` = " . $newStatus;

query execution...

I want to write the same query with Query Builder, looks like he can't do stuff like that.

0 Answers
Related