Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'enum'

  • Loading branch information...
commit 0711f6fb6e93fd5bd1874ec1002f179de9b1d481 2 parents c696d48 + a2144ac
@rozwell authored
View
3  generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -165,6 +165,9 @@ protected function getDefaultValueString(Column $col)
throw new EngineException(sprintf('Default Value "%s" is not among the enumerated values', $val));
}
$defaultValue = array_search($val, $valueSet);
+ if ($col->getPhpType() == 'string') {
+ $defaultValue = "'$defaultValue'";
+ }
} elseif ($col->isPhpPrimitiveType()) {
settype($val, $col->getPhpType());
$defaultValue = var_export($val, true);
View
6 generator/lib/builder/om/PHP5PeerBuilder.php
@@ -416,7 +416,11 @@ protected function addEnumColumnAttributes(&$script)
" . $this->getPeerClassname() . "::" . $this->getColumnName($col) . " => array(
";
foreach ($col->getValueSet() as $value) {
- $script .= " " . $this->getStubPeerBuilder()->getClassname() . '::' . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . ",
+ $script .= " ";
+ if ($col->getPhpType() == 'string') {
+ $script .= $this->getStubPeerBuilder()->getClassname() . '::' . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . " => ";
+ }
+ $script .= $this->getStubPeerBuilder()->getClassname() . '::' . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . ",
";
}
$script .= " ),";
View
6 generator/lib/model/Column.php
@@ -246,6 +246,9 @@ protected function setupObject()
$valueSet = explode(',', $this->getAttribute("valueSet"));
}
$valueSet = array_map('trim', $valueSet);
+ if ($this->getPhpType() == 'string') {
+ $valueSet = array_combine($valueSet, $valueSet);
+ }
$this->valueSet = $valueSet;
} elseif (preg_match('/enum\((.*?)\)/i', $this->getAttribute('sqlType', ''), $matches)) {
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
@@ -257,6 +260,9 @@ protected function setupObject()
$valueSet[] = trim($value, " '");
}
}
+ if ($this->getPhpType() == 'string') {
+ $valueSet = array_combine($valueSet, $valueSet);
+ }
$this->valueSet = $valueSet;
}
View
10 generator/lib/platform/DefaultPlatform.php
@@ -373,7 +373,11 @@ public function getColumnDefaultValueDDL(Column $col)
} elseif ($col->getType() == PropelTypes::BOOLEAN || $col->getType() == PropelTypes::BOOLEAN_EMU) {
$default .= $this->getBooleanString($defaultValue->getValue());
} elseif ($col->getType() == PropelTypes::ENUM) {
- $default .= array_search($defaultValue->getValue(), $col->getValueSet());
+ $v = array_search($defaultValue->getValue(), $col->getValueSet());
+ if ($col->getPhpType() == 'string') {
+ $v = "'$v'";
+ }
+ $default .= $v;
} elseif ($col->isPhpArrayType()) {
$value = $this->getPhpArrayString($defaultValue->getValue());
@@ -1239,13 +1243,13 @@ public function getColumnBindingPHP($column, $identifier, $columnValueAccessor,
rewind($columnValueAccessor);
}";
}
-
+/* @var $column Column */
$script .= sprintf(
"
\$stmt->bindValue(%s, %s, %s);",
$identifier,
$columnValueAccessor ,
- PropelTypes::getPdoTypeString($column->getType())
+ PropelTypes::getPdoTypeString($column->isEnumType() && $column->getPhpType() == 'string' ? PropelTypes::VARCHAR : $column->getType())
);
return preg_replace('/^(.+)/m', $tab . '$1', $script);
View
2  test/testsuite/generator/model/ColumnTest.php
@@ -220,7 +220,7 @@ public function testCommaInEnumValueSet()
$database->addTable($table);
$database->setPlatform($platform);
- $column->loadFromXML(array('valueSet' => 'Foo, Bar, "Foo, Bar"'));
+ $column->loadFromXML(array('type' => PropelTypes::ENUM, 'valueSet' => 'Foo, Bar, "Foo, Bar"'));
$valueSet = $column->getValueSet();
$this->assertCount(3, $valueSet);
Please sign in to comment.
Something went wrong with that request. Please try again.