1

I started with the ZendSkeletonApplication and added a model extending Zend\Db\TableGateway\TableGateway. I have the following method:

public function findByType($type) {
    $rowset = $this->select('type' => $type);
    return $rowset;
}

This works, but now if i do this:

$foo = $table->findBytype('foo');
$bar = $table->findBytype('bar');

the first one works, the query it executes is:

SELECT * FROM table WHERE 'type' = 'foo'

The second one however executes the following query:

SELECT * FROM table WHERE 'type' = 'foo' AND 'type' = 'bar'

is this expected behavior? If so how can i have the second time i call the method execute the following query:

SELECT * FROM table WHERE 'type' = 'bar'

thanks in advance!

GingerHead
  • 8,130
  • 15
  • 59
  • 93
user458753
  • 147
  • 2
  • 3
  • 15
  • Turns out it was just a minor bug in the zf2 beta3 that has allready been fixed in the latest github version. – user458753 Apr 25 '12 at 07:43

1 Answers1

8

Should use select in tableGateway like this:

$select = $this->getSql()->select();
$select->where(array('type' => 'foo'))
    ->where(array('type' => 'bar'));
$rowset = $this->selectWith($select);

select() will be reset the where() paramters when you call it next time.

See more usage in my blog: http://avnpc.com/pages/advanced-database-select-usage-in-zf2

AlloVince
  • 1,655
  • 11
  • 18
  • Is there an english version of your blog? The snippets are well done, but I get everything in chinese and google tries to translate it in german, that's kind of a funny experience ;-) – pia-sophie Jul 28 '17 at 10:06