tags:

views:

77

answers:

1
$this->model = Doctrine::getTable('Model');

$model = $this->model->find(1);
var_dump($model->id);
// returns: string '1' (length=1)

var_dump($model->toArray());
// returns: array
//            'id' => null
//            ...

Why does that happen?

+1  A: 

Ok, just found out, it has to do with the __construct() in my model. I take that out, I get an id in my array.

So I guess my next question would be, how can I use __construct() and still use the toArray() function?

(Oh, and yes, of course, am calling the parent::__construct()...)


I found the answer to my own question.

  public function __construct()
  {
    parent::__construct(Doctrine::getTable('Model'));
  }

You have to pass a new instance of Doctrine_Table to the Doctrine_Record __construct() method.

Even after I found the answer, I couldnt find it online, so I am leaving this here, in case someone else needs it.

tilman
Good find, thanks for sharing!
BenV