class MyViews extends Zend_Db_Table_Abstract
{
protected $_name = 'myviewtable'; /* name of view mysql */
/ *
- Purpose: Using a view as a model of data, but ...
- Zend_Db_Table can not be used if there is no primary key
- As we can not define a primary key to MySQL
- I strongly _setupPrimaryKey method of Class Zend_Db_Table_Abstract giving
a primary key
- Definition: _setupPrimaryKey () gives the name of the primary key default
searching describeTable ();
verifies that the primary key is part of the $ _cols.
- By redefining this method, you can specify a primary key manually.
* /
protected function _setupPrimaryKey()
{
$this->_primary = 'id'; /* name of colum of my view mysql */
parent::_setupPrimaryKey();
}
}
?>
Sébastien Cramatte wrote:
>
> Hello,
>
> I'm trying to use Zend_Db_Table to query some Mysql 5 views.
>
> When I do the query I obtain this kind of exception :
>
> exception 'Zend_Db_Table_Exception' with message 'A table must have a
> primary key, but none was found' in
> /home/vhosts/d/default/library/Zend.SVN/Db/Table/Abstract.php:705
>
> A workaround is to set the protected variable $_primary to some
> column but this not very clean ...
>
> So my question how can I bypass primary keys check when I query views ?
>
> Regards
>
>
--
View this message in context: http://www.nabble.com/Zend_Db_Table-and-Mysql-Views-tp20034707p20378583.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论