diff --git a/library/Zend/Paginator/Adapter/DbSelect.php b/library/Zend/Paginator/Adapter/DbSelect.php index 4e973523d5b..3919de15a91 100644 --- a/library/Zend/Paginator/Adapter/DbSelect.php +++ b/library/Zend/Paginator/Adapter/DbSelect.php @@ -109,6 +109,13 @@ public function count() $select->reset(Select::ORDER); $select->reset(Select::GROUP); + // get join information, clear, and repopulate without columns + $joins = $select->getRawState(Select::JOINS); + $select->reset(Select::JOINS); + foreach ($joins as $join) { + $select->join($join['name'], $join['on'], array(), $join['type']); + } + $select->columns(array('c' => new Expression('COUNT(1)'))); $statement = $this->sql->prepareStatementForSqlObject($select); diff --git a/tests/ZendTest/Paginator/Adapter/DbSelectTest.php b/tests/ZendTest/Paginator/Adapter/DbSelectTest.php index fd781c783c7..ac21f28d5e8 100644 --- a/tests/ZendTest/Paginator/Adapter/DbSelectTest.php +++ b/tests/ZendTest/Paginator/Adapter/DbSelectTest.php @@ -62,7 +62,17 @@ public function testCount() { $this->mockSelect->expects($this->once())->method('columns')->with($this->equalTo(array('c' => new Expression('COUNT(1)')))); $this->mockResult->expects($this->any())->method('current')->will($this->returnValue(array('c' => 5))); - $this->mockSelect->expects($this->exactly(5))->method('reset'); // called for columns, limit, offset, order + + $this->mockSelect->expects($this->exactly(6))->method('reset'); // called for columns, limit, offset, order + $this->mockSelect->expects($this->once())->method('getRawState')->with($this->equalTo(Select::JOINS)) + ->will($this->returnValue(array(array('name' => 'Foo', 'on' => 'On Stuff', 'columns' => array('foo', 'bar'), 'type' => Select::JOIN_INNER)))); + $this->mockSelect->expects($this->once())->method('join')->with( + 'Foo', + 'On Stuff', + array(), + Select::JOIN_INNER + ); + $count = $this->dbSelect->count(); $this->assertEquals(5, $count); }