monmonja
monmonja

Reputation: 2264

zend mapping one to many fetchall

I have 2 tables user and user_comment where user has many user_comments, i laid down the mapping being

User
$_dependentTables = array('User_Comments);

and

User_Comments
$_referenceMap = array(
  'User' => array(
    'columns' => 'id',
    'refTableClass' => 'User',
    'refColumns' => 'id'
  )
);

Is there a way for me to do user->fetchAll() and get the user_comments without doing loop query (in cakephp it will do one query on user_comments where in (ids) then format it back to an array but i cant use cake). Is this possible in zend with me doing it manually? Thanks

Upvotes: 1

Views: 647

Answers (1)

Pushpendra
Pushpendra

Reputation: 4392

Try this one

$sql=$this->getAdapter()->select()
                        ->from("user_comment")
                        ->join("user", "user.id=user_comment.userid")
                        ->where("user_comment.id=?",$userId);

$result=$this->getAdapter()->query($sql)->fetchAll();

This might help u....

Upvotes: 2

Related Questions