madcorp / zfdatagrid

Automatically exported from code.google.com/p/zfdatagrid
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

MassAction with Zend_Select as Source -> PrimaryKey Error #874

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a select object with a where clause
CODE: 
$where = "(status = 'Open' OR (status2 IS NULL AND status3 = 'used')) AND 
release in (SELECT release_id FROM subscription WHERE user_id = $user_id )";
$select = $db->select()->from('bugs')->where($where);

2. Use the select as a Bvb_Grid source:
$source = new Bvb_Grid_Source_Zend_Select($select);
$grid->setSource($source);

3. Add MassAction to the grid:
CODE:$actions = new Bvb_Grid_Mass_Actions();
$actions->setMassActions(array(array('url' => $grid->getUrl(),
            'caption' => 'Remove (Nothing will happen)',
            'confirm' => 'Are you sure?')));
$grid->setMassActions($actions);

What is the expected output? What do you see instead?

Expected a working grid layout. Instead the following error is displayed:

( ! ) Fatal error: Uncaught exception 'Bvb_Grid_Exception' with message 'No 
primary key defined in table. Mass actions not available' in 
C:\xampp\htdocs\Project\library\Bvb\Grid.php on line 4530
( ! ) Bvb_Grid_Exception: No primary key defined in table. Mass actions not 
available in C:\xampp\htdocs\Project\library\Bvb\Grid.php on line 453

setPrimaryKey is not provided for Bvb_Grid_Source_Zend_Select ONLY for 
Bvb_Grid_Source_Array.

Please insert the appropriate values;
                    Zend Framework version: 1.11.11
ZFDatgrid Version (Bvb_Grid::getVersion()): 0.8
                          Operating system: Windows NT MyPC 5.1 build 2600 (Windows XP Professional Service Pack 3) i586 
                               PHP Version: 5.3.8
               Database Server and version: MySQL 5.5.16 
                          Source Adatapter: vb_Grid_Source_Zend_Select

Please provide any additional information below:

Problem described as above only occures when using MassAction and 
Bvb_Grid_Source_Zend_Select as source!

Original issue reported on code.google.com by goede...@elation-studios.de on 27 Jul 2012 at 1:00

GoogleCodeExporter commented 9 years ago
Fixed this issue through enabeling setting a primary key for Zend_Select. To 
enable this property it was necessary to modify one of the ZFDatagrid Core 
files. After my modification you can use the setPrimaryKey method as known from 
other sources.

- File: Bvb/Grid/Source/Zend/Select.php
- Add the following snipet below line 1460:

        // Modified by: goedecke@net-studios.de
        // Date: 27. July 2012 - 15:37
        // In case no primary key is set use manual set variable
        if (empty ($keys))  {
            $keys = $this->_primaryKey;
        }

        return $keys;

    }

        /**
         * Modified by: goedecke@net-studios.de
         * Date: 27. July 2012 - 15:41
         * @param array $pk
         * @return Bvb_Grid_Source_Zend_Select 
         */

        public function setPrimaryKey(array $pk)
        {
            $this->_primaryKey = $pk;
            return $this;
        }

- Insert the following line in the controller you are using to display the 
select:
        $source->setPrimaryKey(array ('pk1'));

Issue solved ;-)

Find attached my modified Select.php.

Have fun.

Net-Studios - Webdesign Stuttgart / Germany

Original comment by kevin.go...@gmail.com on 5 Sep 2012 at 2:09

Attachments:

GoogleCodeExporter commented 9 years ago
Forgot one step:

Add the following line at the beginning:

protected $_primaryKey;

To introduce the variable ;-)

Regards

Original comment by kevin.go...@gmail.com on 5 Sep 2012 at 2:10