Created
January 27, 2014 15:51
-
-
Save Saeven/8651055 to your computer and use it in GitHub Desktop.
Subquery in ZF2 in AbstractTableGateway implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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