2007-09-19 19:39:59 +00:00
Doctrine offers various table options. All table options can be set via {{Doctrine_Record::option($optionName, $value)}}.
For example if you are using MySQL and want to use INNODB tables it can be done as follows:
<code type="php">
class MyInnoDbRecord extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->option('type', 'INNODB');
}
}
</code>
In the following example we set the collate and character set options:
<code type="php">
class MyCustomOptionRecord extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->option('collate', 'utf8_unicode_ci');
$this->option('charset', 'utf8');
}
}
</code>
2008-06-14 14:46:16 +00:00
It is worth noting that for certain databases (Firebird, MySql and PostgreSQL) setting the charset option might not be enough for Doctrine to return data properly. For those databases, users are advised to also use the setCharset function of the database connection:
<code type="php">
Doctrine_Manager::connection($name)->setCharset("utf8");
</code>
2007-09-19 19:39:59 +00:00
Doctrine offers the ability to turn off foreign key constraints for specific Models.
<code type="php">
class MyCustomOptionRecord extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS);
}
}
</code>