2008年10月19日星期日

Re: [fw-mvc] Zend_Db_Table and Mysql Views

Hi Sébastien,


I don't create a Model Object for my views. Instead, I just declare views to be used with my table Models.
For example, I have this two tables:

people (
  person_id,
  name,
  surname,
  birthday
)

accounts (
  person_id,
  username,
  password
)

And this view:

vw_accounts (
  SELECT p.*, a.username
  FROM accounts AS a
  INNER JOIN people AS p ON p.person_id = a.person_id;
)

Then, I have the model that extends Zend_Db_Table_Abstract:

class Person extends Zend_Db_Table_Abstract
{
    protected $_name = 'people';
    protected $_primary = 'person_id';
    protected $_views = array('accounts' => 'vw_accounts');
}


When I need to retrieve data from a view, then I just change the from arguments to retrieve from some of my views.
I hope it helps.


Best regards,


--
Ramses Paiva
Software Architect
Sourcebits Technologies
www.sourcebits.com

On Sat, Oct 18, 2008 at 1:24 PM, SŽébastien Cramatte <scramatte@zensoluciones.com> wrote:
When I  query a  table it's works perfectly  ...
The problem occurs only when I query  a Mysql "view"



Muhammad Saifullah escribió:
pls check these.
1.when you create table then did you set primary key column?
2.if you set ,then when you override protected variable then is overrided variable`s value matched with tables`s primary key column?if not matched then you can see this error...
pls tell me your writing condition.whether i cant give you a write solution


On Fri, Oct 17, 2008 at 10:02 PM, SŽébastien Cramatte <scramatte@zensoluciones.com <mailto:scramatte@zensoluciones.com>> 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




--
Sébastien Cramatte  / IT engineer

ZEN SOLUCIONES
Ingeniera de redes y soluciones informáticas globales

Plaza Sandoval, 5, piso 4b
30004 Murcia - ESPAÑA

+34 902 907 377
contacto@zensoluciones.com

--

www.zensoluciones.com
tienda.zensoluciones.com
concentre.zensoluciones.com

--

This e-mail is privileged and may contain confidential information intended only for the person(s) named above. If you receive this e-mail in error, please notify the sender immediately and delete it. E-mail and internet transmissions can't be warrant privacy, integrity or correct reception. The sender will not be liable for any damages resulting.

Este mensaje va dirigido, de manera exclusiva, a su destinatario y puede contener información confidencial. En caso de haber recibido este mensaje por error, informe al emisor inmediatamente y proceda a su eliminación. El correo electrónico y las comunicaciones por medio de Internet no permiten garantizar la confidencialidad de los mensajes transmitidos, así como tampoco su integridad o su correcta de recepción. El emisor no asume responsabilidad alguna por tales circunstancias.

Ce message est destiné exclusivement à son destinataire et peut contenir des informations confidentielles. En cas de réception d'un tel message par erreur, informez l'expéditeur immédiatement et procédez à son effacement. Il n'est pas possible de garantir la confidentialité, l'intégrité ou la réception correcte du courrier électronique ainsi que des communications par internet. L'expéditeur ne peut être tenu pour responsable d'éventuels dommages commis.

没有评论: