Views: 5.5K
Replies: 0
Archived
|
Persistance of Shopping CartAs others before me I also would like some verification on the process of saving a cart - as I'm trying to implement some best practices in my development - and I stall over how I "should" be doing things.
If I were to venture a guess - I would pass the entire shopping cart & user back - and then just persist each item. But my feeling and ignorance are telling me I'm missing something. And then I get more insecure about the approach once we allow for updating of said orders. The cart app isn't a perfect example - but let's say it was a recipe catalog - as they are similar. I can create and save a recipe. Then as I refine my recipe (at a later date) I can add/remove/update various ingredients. Would it be a better approach to persist each ingredient to the DB as it happens? Or to work with the recipe - and save it only at one time? If I persist as it happens - there's no "undo" capability. Which would lead me to doing it all in the recipe "Save" type method. But if that's the case - what would be a good ("best practice"?) approach to updating some ingredients, creating others, and removing non-existant ones in one process? It seems to me that you could easily run into a number of DB calls. Is that just the inevitability of it all? I'm sure I'm missing the obvious, or over-reading into things - and would really appreciate any sort of slap in the head to snap me out of this! Andrew Walker, Feb 03, 2011
Thanks Greg - I didn't notice any notification of your reply - hence my long delay in response.
It makes sense and having your confirmation makes me feel all the better about it! Thanks again!
May 12, 2011
Hi Andrew.
In your recipe scenario, you should consider each RecipeIngredient i.e. a mapping between a recipe object and an ingredient object as a unit of work and persist / update / delete each recipeingredient in its own operation. Selecting the necessary ingredient persists the mapping (recipe > ingredient) and returns either the new list of ingredients, or a single ingredient which is then added to the DOM. From a usability point of view you could do this in an Ajax fashion so that a) the user experience is better b) you reduce the overhead in bringing other data / bindings on the page
Feb 09, 2011
|