3

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

yes, and then use a foreach(or a loop of your choice) to get desired fields out of the rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.