Skip to content

Instantly share code, notes, and snippets.

@dsoares
Forked from havvg/MyModel.php
Created March 7, 2017 20:06
Show Gist options
  • Save dsoares/b8c01ef8dc213d5adf4a9aa20da68cb3 to your computer and use it in GitHub Desktop.
Save dsoares/b8c01ef8dc213d5adf4a9aa20da68cb3 to your computer and use it in GitHub Desktop.

Revisions

  1. @havvg havvg revised this gist Nov 27, 2012. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions MyModel.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?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);
    }
    }
    }
  2. @havvg havvg revised this gist Dec 8, 2011. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions MyModelTest.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?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));
    }
    }
  3. @havvg havvg revised this gist Dec 8, 2011. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions MyModelPeer.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?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,
    ),
    );
    }
  4. @havvg havvg created this gist Dec 8, 2011.
    4 changes: 4 additions & 0 deletions schema.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- ... -->
    <column name="type" type="enum" valueSet="IN,OUT" sqlType="ENUM('IN','OUT')" required="true" />
    <!-- ... -->