I would use the join method. Calling out to the database is an expensive operation, so I try to minimize the number of calls. Also, try not to think in terms of loops when you consider data, it is more based in set theory.
Or do you rather execute one large SQL statement in the UserManager model.
For instance something like:

function userManager::getAllByCity( $city )
{

  $users = array();

  $sql = '
    SELECT
      columns
    FROM
      user
    LEFT JOIN
       image
    LEFT JOIN
       video
    # etc....
  ';

  $result = $db->execute( $sql );

  foreach( $result as $row )
  {

    if( !isset( $users[ $row[ 'id' ] ] ) )
    {
       $users[ $row[ 'id' ] ] = new User_Model();
    }

    if( !$users[ $row[ 'id' ] ]->hasImage( $row[ 'imageId' ] ) )
    {
      $users[ $row[ 'id' ] ]->addImage( $row[ 'imageId' ], $row[
'imageLocation' ] );
    }

    if( !$users[ $row[ 'id' ] ]->hasVideo( $row[ 'videoId' ] ) )
    {
      $users[ $row[ 'id' ] ]->addVideo( $row[ 'videoId' ], $row[
'videoLocation' ] );
    }
    // etc....
  }

  return $users;

}

$users = $userManager->getAllByCity( 'Amsterdam' );


Reply via email to