0

In this code :

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $records = new Application_Model_Mapper_Record();
        $this->view->records = $records->fetchAll(array('type = ?' => 0));
    }


}

... fetchAll() ignores my $where clause and retrieves all the records instead of only retrieving records with type=0.

I tried with array('type = 0'), same problem. I did a var_dump($where) in my mapper fetchAll() method, but nothing particular appeared, the array seems to be okay.

What should I do ? I have absolutely no idea why it does that, and it appears I'm the only one to have this issue on the Internets.

ryancey
  • 1,037
  • 2
  • 11
  • 27

1 Answers1

0
$rowSet = $this->dbTable->fetchAll($where = null, $order = null, $count = null, $offset = null);

Just replace with $rowSet = $this->dbTable->fetchAll($where, $order, $count, $offset); in your mapper class. Because when you call this method, you assign null to the method arguments. It's method call, not initialize.

  • Same problem. Nothing happened. Should I `var_dump($where)` upper in the architecture ? For example, in the "real" `fetchAll()` method from the Zend lib? I don't even know how to debug this. – ryancey Sep 12 '13 at 15:43
  • It works fine with `Model_DbTable_Records` though. When I replace `$where = null` with `$where` in the mapper `fetchAll()` and use it, it works. Looks like `$where` is set to `null` by default, even when it isn't empty. Why? – ryancey Sep 13 '13 at 09:00
  • Ok, I think I got it. `$where` is set to `null` by default in the mapper if it's empty, and then call the `dbTable->fetchAll()` which do the same. But no need, because `$where` does have a value anyway (`null`, or the actual `WHERE` condition array). Still, I can't figure out why `dbTable->fetchAll()` sets `$where` to null as it isn't empty... – ryancey Sep 13 '13 at 09:05
  • $rowSet = $this->dbTable->fetchAll($where = null, $order = null, $count = null, $offset = null); Just replace with $rowSet = $this->dbTable->fetchAll($where, $order, $count, $offset); in your mapper class. Because when you call this method, you assign null to the method arguments. It's method call, not initialize – Bogdan Solomykin Sep 13 '13 at 09:22
  • Yeah, I did that. Thanks for your time. You can post it as an answer, so I can validate it, if you want. – ryancey Sep 13 '13 at 09:40