Added special logic for foreignKey columns

This commit is contained in:
Moritz Schroeder 2016-02-17 19:51:22 +01:00
parent 51fb7fd287
commit edfb13c388
2 changed files with 13 additions and 3 deletions

View file

@ -78,7 +78,7 @@ EOT
foreach ($manager->getDataModels() as $dataModel) { foreach ($manager->getDataModels() as $dataModel) {
foreach ($dataModel->getDatabases() as $database) { foreach ($dataModel->getDatabases() as $database) {
$this->createFormTypeFromDatabase($this->bundle, $database, $models, $output, $force); $this->createFormTypeFromDatabase($bundle, $database, $models, $output, $force);
} }
} }
} }

View file

@ -10,6 +10,7 @@
namespace Propel\Bundle\PropelBundle\Form; namespace Propel\Bundle\PropelBundle\Form;
use Propel\Generator\Model\ForeignKey;
use Propel\Generator\Model\Table; use Propel\Generator\Model\Table;
use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface;
@ -52,9 +53,18 @@ class FormBuilder
{ {
$buildCode = ''; $buildCode = '';
foreach ($table->getColumns() as $column) { foreach ($table->getColumns() as $column) {
if (!$column->isPrimaryKey()) { if ($column->isPrimaryKey()) {
$buildCode .= sprintf("\n \$builder->add('%s');", lcfirst($column->getPhpName())); continue;
} }
$name = $column->getPhpName();
// Use foreignKey table name, so the TypeGuesser gets it right
if ($column->isForeignKey()) {
/** @var ForeignKey $foreignKey */
$foreignKey = current($column->getForeignKeys());
$name = $foreignKey->getForeignTable()->getPhpName();
}
$buildCode .= sprintf("\n \$builder->add('%s');", lcfirst($name));
} }
return $buildCode; return $buildCode;