Enum is mysql specific, so, you cannot have an enum in your schema.xml.
If you don't want to create another table to store the different
possible values, you can simulate an enum very easily.
Imagine you have a status column in you article table you want to be an
enum with values like ('open', 'closed'). Simply declare the status
column as integer and then (not tested):
In your ArticlePeer.php class:
class ArticlePeer...
{
static protected $STATUS_INTEGERS = array('open', 'closed');
static protected $STATUS_VALUES = null;
static public function getStatusFromIndex($index)
{
return self::$STATUS_INTEGERS[$index];
}
static public function getStatusFromValue($value)
{
if (!self::$STATUS_VALUES)
{
self::STATUS_VALUES = array_flip(self::$STATUS_INTEGERS);
}
$values = strtolower($value);
if (!isset(self::STATUS_VALUES[$value])
{
throw new PropelException(sprintf('Status cannot take "%s" as a
value', $value));
}
return self::STATUS_VALUES[strtolower($value)];
}
}
In your Article.php class:
class Article
{
public function setStatusName($value)
{
$this->setStatus(self::getStatusFromValue($value));
}
public function getStatusName()
{
return self::getStatusFromIndex($this->getStatus());
}
}
Fabien
Dealing with ENUM with Symfony, Propel and Mysql
最新推荐文章于 2019-08-21 17:17:10 发布