Op Wednesday 20 May 2009 05:18:03 schreef Deanna Bonds:
> 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' );
Hi,
I'd go for neither of these methods. Create models for Users, Videos and
Images and connect them together by using the relational features of Db_Table.
Then call the getter for images only when required. You don't need to get the
images at any time. Also, I suggest you cache the results so you don't need to
pull the database every time. If a user changes his profile, delete the cache
file and it's immediately updated in cache.
R, Jurian
--
Jurian Sluiman
Soflomo.com