1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/manual/docs/Getting started - Setting table definition - Enum emulation.php

24 lines
928 B
PHP
Raw Normal View History

2007-04-14 01:49:11 +04:00
Doctrine offers enum data type emulation for all databases. The enum data type of Doctrine maps to
integer on database. Doctrine takes care of converting the enumerated value automatically to its valuelist equivalent when a record is being fetched
and the valuelist value back to its enumerated equivalent when record is being saved.
2007-04-14 01:49:11 +04:00
<code type="php">
class Article extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("title","string", 200);
// maps to TINYINT on mysql
$this->hasColumn("section", "enum", 2, array('values' => array("PHP","Python","Java","Ruby")));
}
}
$article = new Article;
$article->title = 'My first php article';
// doctrine auto-converts the section to integer when the
// record is being saved
$article->section = 'PHP';
$article->save();
// on insert query with values 'My first php article' and 0
// would be issued
</code>