Skip to content

Instantly share code, notes, and snippets.

@fabiocicerchia
Created February 24, 2012 16:26
Show Gist options
  • Save fabiocicerchia/1901868 to your computer and use it in GitHub Desktop.
Save fabiocicerchia/1901868 to your computer and use it in GitHub Desktop.
Doctrine 1.x - Force an ID
<?php
$manager = Doctrine_Manager::getInstance();
$connection = $manager->getCurrentConnection();
// BANAL EXAMPLE
$id = 1;
$element = Doctrine::getTable('SampleObject')->find($id);
$element->setId(2);
$connection->unitOfWork->saveGraph($element, true); // If object already exists true, then replace it. Otherwise false to insert a new record.
<?php
class SampleObject extends Doctrine_Record
{
public function setId($value)
{
$this->_values['id'] = $value;
$this->_set('id', $value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment