Skip to content

Instantly share code, notes, and snippets.

@Saeven
Created January 27, 2014 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saeven/8651055 to your computer and use it in GitHub Desktop.
Save Saeven/8651055 to your computer and use it in GitHub Desktop.
Subquery in ZF2 in AbstractTableGateway implementation
public function fetchAllWithVotes()
{
$resultset = $this->select( function( Select $select ){
$sub = new Select( 'votes' );
$sub->columns( array( 'total' => new Expression('COUNT(*)') ) )
->where( 'songs.id = votes.song_id' );
$select->columns(
array(
'id',
'title',
'ytlink',
'votes' => new Expression( '?', array( $sub_query ) ),
)
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment