Search code examples
modelsymfony-1.4extend

Symfony 1.4 extend model error


After read and re-read Symfony's 1.4 doc and research enough in Google, I decided ask about this here. I have a model called "ot" and I want to have a method getUnreadMsg() to get some specific data.

This is the class:

class ot extends Baseot {

    public function __toString() {
        return $this->getNombre();
    }

    public function getNumberOfUnreadMsgs() {
        $mensajes = Doctrine_Core::getTable('mensaje')
                ->createQuery('m')
                ->where('m.ots_id=' . $this->getId())
                ->andWhere('m.estado=0')
                ->orderBy('m.created_at DESC')
                ->execute();
        return count($mensajes);

    }
}

And this how I used it in the view layer:

<?php foreach ($ots as $ot): ?>
  ....
  <?php echo $ot->getNumberOfUnreadMsgs();   ?>
  ....
<?php endforeach; ?>

And this is the error I'm getting:

Unknown record property / related component "number_of_unread_msgs" on "ot"

Solution

  • The code cannot found that method for some reason.

    One thing I've noticed is the case is not right. It should be Ot not ot. Not sure if that's causing the issue but that's definitely wrong. In your confif/doctrine/ot.yml change the first line to Ot and rebuild your model.

    Make the necessary updates in your code. It should work.