2008年8月7日星期四

Re: [fw-db] Using a Mysql View as a Table

Problem Solved,

if in the model you add the following line:
protected $_primary = 'p_id'; < where p_id is the field you mark as primary.

then it works.

Patrick

On Aug 7, 2008, at 2:26 PM, ZF wrote:

Hi guys,

How can I use a Mysql View as a Table Model in ZF?

I'm now receiving this error, which is totally right:
A table must have a primary key, but none was found

since views don't have Pkeys.

The only way i can use views now is by doing this:
$select = $table->select() ->setIntegrityCheck(false)
                        ->from('v_myview')
                        ->where('c_username = ?',"$loggedinuser->username");
        
        
        $results = $table->fetchAll($select);

I think there should be a way to avoid this long road.
and i'm first initiating a 'useless' table since afterwards i'm selecting the from from another 'table(view)',
so performance wise this isn't right either.

Thanks,
Patrick

没有评论: