Created
February 24, 2012 16:26
-
-
Save fabiocicerchia/1901868 to your computer and use it in GitHub Desktop.
Doctrine 1.x - Force an ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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