741TestCase.php 1.88 KB
Newer Older
pookey's avatar
pookey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php


class Doctrine_Ticket_741_TestCase extends Doctrine_UnitTestCase
{

    public function prepareData() 
    { }

    public function prepareTables()
    {
        $this->tables = array('Parent741', 'Child741');
        parent::prepareTables();
    }

    public function testTicket()
    {
        $moo = new Parent741();
        $moo->amount = 1000;
        $cow = new Child741();

        $moo->Cows[] = $cow;
        $cow->Moo = $moo;
        $moo->save();
        $this->assertEqual($moo->amount, 0);
    }

}



class Parent741 extends Doctrine_Record
{
34
  public static function initMetadata($class)
pookey's avatar
pookey committed
35
  {
36
    $class->setColumn('id', 'integer', 4, array (
pookey's avatar
pookey committed
37 38 39 40 41
      'primary' => true,
      'autoincrement' => true,
      'notnull' => true,
    ));

42 43
    $class->setColumn('amount', 'integer');
    $class->hasMany('Child741 as Cows', array('local' => 'id', 'foreign' => 'moo_id'));
pookey's avatar
pookey committed
44 45 46 47 48
  }
}

class Child741 extends Doctrine_Record
{
49
  public static function initMetadata($class)
pookey's avatar
pookey committed
50
  {
51
    $class->setColumn('id', 'integer', 4, array (
pookey's avatar
pookey committed
52 53 54 55 56
      'primary' => true,
      'autoincrement' => true,
      'notnull' => true,
    ));

57 58
    $class->setColumn('moo_id', 'integer');
    $class->hasOne('Parent741 as Moo', array('local' => 'moo_id', 'foreign' => 'id'));
pookey's avatar
pookey committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  }

  public function postInsert($e)
  {
    
    //echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
    $this->Moo->amount = 0;
    //echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
    $this->Moo->save();
    //echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
    $this->Moo->refresh();
    //echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
    /*
      This outputs the following
      State: 6         Amount: 1000
      State: 6         Amount: 0
      State: 6         Amount: 0
      State: 3         Amount: 1000

    */
  }
}