Hi all,

I'm faced with a recurring design issue for which I haven't found a good
implementation yet. So I was wondering how you would generally deal with
this.

Let's say I have a website with user profiles. Imagine the DB model has
a base table 'user' and a few child tables (for instance to link images
and videos to this user). So basically (in hierarchal order):

- User
 - UserImage
 - UserVideo

Based on this I would like to create a frontend UserManager model that
returns User models. This UserManager model could have methods like:

- getById()
- getAllByAge()
- getAllByCity()

or similar methods and what have you. These methods in my opinion should
return collections of User models (basically instances of a User object).

My design issue is the following:

Imagine that sometimes I only need some basic info about the User with
perhaps one (main profile) image. For instance for some search result
functionality.

The other time around I might  only need all images. For
instance when you arrived on the User's profile and you viewing the
images section of that User.


Now, on the one hand I would want the UserManager to issue one big SQL
statement with lots of joins that creates and 'fills' the instances of
User models, as to minimize SQL queries to the DB.

But on the other hand I don't always need all the information about the
User as per my previous example situations. So I would rather lazy load
the stuff about the User only when I need it and have it implemented in
the User model.

How would I approach this in a consistent manner, such that I don't have
SQL statements scattered all around my UserManager and User model?
Or would you perhaps create different UserManager models for these
different tasks?
Perhaps my whole initial approach could use some rethinking. If you
think so, don't hesitate to give me a heads up about it please.

I'ld love to read about how you generally approach these kinds of
situations.
Thanks in advance.


-- 
View this message in context: 
http://www.nabble.com/-OT--General-design-question-tp23623977p23623977.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to