R – “Hierarchical” rowsets in Zend Framework

databasemodelzend-framework

I have two tables – let's call them Customers and Orders. It's a 1:n relationship, where each Order is placed by one Customer, and one Customer can have many orders.

The Web app is written in Zend Framework. My goal is to query a customer from the database, and get their 10 most recent orders (for example), and to have all this information bundled into a single object that can be passed between several controllers/views/helpers. I want to do all the querying up-front in the initial controller, and then create a single object (or whatever) that can be handed from code to code, with no further querying.

I'd also like to minimize querying as much as possible in that initial step. That is, I know one way would be to query the desired customers, enumerate through them, and construct a custom object (or just an array) containing their values. During that enumeration, I'd query each customer's orders and tack that info on to each customer object. I'd then pass the collection of customer objects around.

Short of that rather brute-force approach, is there a better approach for this?

Best Answer

You could implement some kind of caching using memcached, and Zend_Cache, that way you can have the 10 most recent orders, and in any event you insert a new one you just delete the cache for that customer and re-populate it.

Related Topic