Parcourir la source

ZF-2925
- updated manual to document select retrieval parameters
- added constants to demonstrate select usage in Zend_Db_Table_Abstract::select()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15637 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph il y a 16 ans
Parent
commit
32787aac41

+ 5 - 3
documentation/manual/en/module_specs/Zend_Db_Table.xml

@@ -1078,8 +1078,10 @@ $rows = $table->fetchAll($select);
                     <programlisting language="php"><![CDATA[
 $table = new Bugs();
 
-$select = $table->select();
-$select->where('bug_status = ?', 'NEW')
+// retrieve with from part set, important when joining
+$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART); 
+$select->setIntegrityCheck(false)
+       ->where('bug_status = ?', 'NEW')
        ->join('accounts', 'accounts.account_name = bugs.reported_by')
        ->where('accounts.account_name = ?', 'Bob');
 
@@ -1108,7 +1110,7 @@ $rows = $table->fetchAll($select);
                 <programlisting><![CDATA[
 $table = new Bugs();
 
-$select = $table->select()->setIntegrityCheck(false);
+$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false);
 $select->where('bug_status = ?', 'NEW')
        ->join('accounts',
               'accounts.account_name = bugs.reported_by',

+ 5 - 2
library/Zend/Db/Table/Abstract.php

@@ -75,6 +75,9 @@ abstract class Zend_Db_Table_Abstract
     const DEFAULT_CLASS    = 'defaultClass';
     const DEFAULT_DB       = 'defaultDb';
 
+    const SELECT_WITH_FROM_PART    = true;
+    const SELECT_WITHOUT_FROM_PART = false;
+    
     /**
      * Default Zend_Db_Adapter_Abstract object.
      *
@@ -907,11 +910,11 @@ abstract class Zend_Db_Table_Abstract
      * @param bool $withFromPart Whether or not to include the from part of the select based on the table
      * @return Zend_Db_Table_Select
      */
-    public function select($withFromPart = false)
+    public function select($withFromPart = self::SELECT_WITHOUT_FROM_PART)
     {
         require_once 'Zend/Db/Table/Select.php';
         $select = new Zend_Db_Table_Select($this);
-        if ($withFromPart == true) {
+        if ($withFromPart == self::SELECT_WITH_FROM_PART) {
             $select->from($this->info(self::NAME), Zend_Db_Table_Select::SQL_WILDCARD, $this->info(self::SCHEMA));
         }
         return $select;

+ 1 - 1
tests/Zend/Db/Table/Select/TestCommon.php

@@ -221,7 +221,7 @@ abstract class Zend_Db_Table_Select_TestCommon extends Zend_Db_Select_TestCommon
         $select3Text = $select3->__toString();
         $this->assertNotContains('zfaccounts', $select3Text);
         
-        $select4 = $table->select(true);
+        $select4 = $table->select(Zend_Db_Table_Abstract::SELECT_WITH_FROM_PART);
         $select4->setIntegrityCheck(false);
         $select4->joinLeft('tableB', 'tableA.id=tableB.id');
         $select4Text = $select4->__toString();