Created
December 8, 2011 12:53
-
-
Save havvg/1446917 to your computer and use it in GitHub Desktop.
true MySQL ENUM with Propel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyModel extends BaseMyModel | |
{ | |
public function hydrate($row, $startcol = 0, $rehydrate = false) | |
{ | |
try { | |
$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null; | |
$this->type = ($row[$startcol + 1] !== null) ? $row[$startcol + 1] : null; | |
$this->resetModified(); | |
$this->setNew(false); | |
if ($rehydrate) { | |
$this->ensureConsistency(); | |
} | |
return $startcol + 2; | |
} catch (Exception $e) { | |
throw new PropelException("Error populating MyModel object", $e); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyModelPeer extends BaseMyModelPeer | |
{ | |
/** The enumerated values for this table */ | |
protected static $enumValueSets = array( | |
self::TYPE => array( | |
MyModelPeer::TYPE_IN => MyModelPeer::TYPE_IN, | |
MyModelPeer::TYPE_OUT => MyModelPeer::TYPE_OUT, | |
), | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyModelTest extends \PHPUnit_Framework_TestCase | |
{ | |
public function testEnum() | |
{ | |
$obj = new MyModel(); | |
$obj->setType(MyModelPeer::TYPE_IN); | |
$this->assertTrue((bool) $obj->save()); | |
$expected = array( | |
'IN' => 'IN', | |
'OUT' => 'OUT', | |
); | |
$this->assertEquals($expected, MyModelPeer::getValueSet(MyModelPeer::TYPE)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- ... --> | |
<column name="type" type="enum" valueSet="IN,OUT" sqlType="ENUM('IN','OUT')" required="true" /> | |
<!-- ... --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment