简体   繁体   中英

using join() in Zend Model

I would like to create a model using join. This is the code i have:

$userModel = new self;
$select = $userModel->select();
$select->setIntegrityCheck(false)
   ->from(array('u' => 'accounts'),array('username','email'))
   ->where('u.id = ?',$id)
   ->join(array('i' => 'permissions'),'i.user_id = u.id',array('permission_type'));
$user = $userModel->fetchRow($select);

This works perfectly. The only problem is that the permission_type in permissions table has multiple entries. Using this code, I only get the first entry in the model! Is there a way to get around that, and get all the entries?

I believe you might be looking for fetchAll. Like this:

...
$users = $userModel->fetchAll($select);

More information here http://framework.zend.com/manual/1.12/en/zend.db.table.rowset.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM