rewriting tables

This commit is contained in:
Etienne Roudeix
2013-08-28 15:55:38 +02:00
parent 2d370bf9b8
commit 253a0b76d8
5 changed files with 20 additions and 5 deletions

View File

@@ -1017,6 +1017,10 @@ abstract class RewritingUrl implements ActiveRecordInterface
$modifiedColumns = array(); $modifiedColumns = array();
$index = 0; $index = 0;
$this->modifiedColumns[] = RewritingUrlTableMap::ID;
if (null !== $this->id) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . RewritingUrlTableMap::ID . ')');
}
// check the columns in natural order for more readable SQL queries // check the columns in natural order for more readable SQL queries
if ($this->isColumnModified(RewritingUrlTableMap::ID)) { if ($this->isColumnModified(RewritingUrlTableMap::ID)) {
@@ -1086,6 +1090,13 @@ abstract class RewritingUrl implements ActiveRecordInterface
throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
} }
try {
$pk = $con->lastInsertId();
} catch (Exception $e) {
throw new PropelException('Unable to get autoincrement id.', 0, $e);
}
$this->setId($pk);
$this->setNew(false); $this->setNew(false);
} }
@@ -1383,7 +1394,6 @@ abstract class RewritingUrl implements ActiveRecordInterface
*/ */
public function copyInto($copyObj, $deepCopy = false, $makeNew = true) public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{ {
$copyObj->setId($this->getId());
$copyObj->setUrl($this->getUrl()); $copyObj->setUrl($this->getUrl());
$copyObj->setView($this->getView()); $copyObj->setView($this->getView());
$copyObj->setViewId($this->getViewId()); $copyObj->setViewId($this->getViewId());
@@ -1413,6 +1423,7 @@ abstract class RewritingUrl implements ActiveRecordInterface
if ($makeNew) { if ($makeNew) {
$copyObj->setNew(true); $copyObj->setNew(true);
$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
} }
} }

View File

@@ -158,7 +158,7 @@ class RewritingUrlTableMap extends TableMap
$this->setPhpName('RewritingUrl'); $this->setPhpName('RewritingUrl');
$this->setClassName('\\Thelia\\Model\\RewritingUrl'); $this->setClassName('\\Thelia\\Model\\RewritingUrl');
$this->setPackage('Thelia.Model'); $this->setPackage('Thelia.Model');
$this->setUseIdGenerator(false); $this->setUseIdGenerator(true);
// columns // columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('URL', 'Url', 'VARCHAR', true, 255, null); $this->addColumn('URL', 'Url', 'VARCHAR', true, 255, null);
@@ -454,6 +454,10 @@ class RewritingUrlTableMap extends TableMap
$criteria = $criteria->buildCriteria(); // build Criteria from RewritingUrl object $criteria = $criteria->buildCriteria(); // build Criteria from RewritingUrl object
} }
if ($criteria->containsKey(RewritingUrlTableMap::ID) && $criteria->keyContainsValue(RewritingUrlTableMap::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.RewritingUrlTableMap::ID.')');
}
// Set the correct dbName // Set the correct dbName
$query = RewritingUrlQuery::create()->mergeWith($criteria); $query = RewritingUrlQuery::create()->mergeWith($criteria);

View File

@@ -40,7 +40,7 @@ VALUES
(1, 'en_EN', 'euro'), (1, 'en_EN', 'euro'),
(2, 'fr_FR', 'dollar'), (2, 'fr_FR', 'dollar'),
(2, 'en_EN', 'dollar'), (2, 'en_EN', 'dollar'),
(3, 'fr_FR', 'livre'); (3, 'fr_FR', 'livre'),
(3, 'en_EN', 'pound'); (3, 'en_EN', 'pound');

View File

@@ -1441,7 +1441,7 @@ DROP TABLE IF EXISTS `rewriting_url`;
CREATE TABLE `rewriting_url` CREATE TABLE `rewriting_url`
( (
`id` INTEGER NOT NULL, `id` INTEGER NOT NULL AUTO_INCREMENT,
`url` VARCHAR(255) NOT NULL, `url` VARCHAR(255) NOT NULL,
`view` VARCHAR(255), `view` VARCHAR(255),
`view_id` VARCHAR(255), `view_id` VARCHAR(255),

View File

@@ -1094,7 +1094,7 @@
<behavior name="timestampable" /> <behavior name="timestampable" />
</table> </table>
<table name="rewriting_url" namespace="Thelia\Model"> <table name="rewriting_url" namespace="Thelia\Model">
<column name="id" primaryKey="true" required="true" type="INTEGER" /> <column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="url" required="true" size="255" type="VARCHAR" /> <column name="url" required="true" size="255" type="VARCHAR" />
<column name="view" size="255" type="VARCHAR" /> <column name="view" size="255" type="VARCHAR" />
<column name="view_id" size="255" type="VARCHAR" /> <column name="view_id" size="255" type="VARCHAR" />