Permalink
Browse files

'from' method in Select class can accept instance of Select object

  • Loading branch information...
1 parent 04f84c7 commit 3d45ac94c097689d32283027b1894e75a66b01e2 @meniam committed Sep 18, 2012
Showing with 8 additions and 2 deletions.
  1. +2 −2 library/Zend/Db/Sql/Select.php
  2. +6 −0 tests/ZendTest/Db/Sql/SelectTest.php
View
4 library/Zend/Db/Sql/Select.php
@@ -164,8 +164,8 @@ public function from($table)
throw new Exception\InvalidArgumentException('Since this object was created with a table and/or schema in the constructor, it is read only.');
}
- if (!is_string($table) && !is_array($table) && !$table instanceof TableIdentifier) {
- throw new Exception\InvalidArgumentException('$table must be a string, array, or an instance of TableIdentifier');
+ if (!is_string($table) && !is_array($table) && !$table instanceof TableIdentifier && !$table instanceof Select) {
+ throw new Exception\InvalidArgumentException('$table must be a string, array, or an instance of TableIdentifier or Select');
}
if (is_array($table) && (!is_string(key($table)) || count($table) !== 1)) {
View
6 tests/ZendTest/Db/Sql/SelectTest.php
@@ -26,9 +26,15 @@ class SelectTest extends \PHPUnit_Framework_TestCase
*/
public function testFrom()
{
+ $select = new Select;
+ $subselect = new Select();
+ $select->from($subselect);
+ $this->assertSame($subselect, $select->getRawState(Select::TABLE));
+
$select = new Select;
$return = $select->from('foo', 'bar');
$this->assertSame($select, $return);
+
return $return;
}

0 comments on commit 3d45ac9

Please sign in to comment.