There are two basic approaches:

recalculate stock_level at every request.   So instead of being an
attribute, stock_level is a function that loops through the orders to
calculate the stock level.  This seems insane (loop through a million
orders every time we need to figure out how much sugar we have?)  But
for many problems the loops aren't very big, and computer time is
cheaper than computer time.   The advantage of this approach is that
it's "normal": the same information is not stored in more than one
place in the database.   And it can be reasonable by moving some of
the calculations into the database and/or smart caching.

But that's probably not what you want.  Probably you want to set up a
lifecycle state transition on the order, so that when the order
changes from "pending" to "delivered", the ingredients are deleted
from stock.   You'd also set up the permissions so order quantities
cannot be changed after the order is delivered.   You'd also have to
use a transaction or set up optimistic locking so that if two orders
are delivered simultaneously stock level changes don't collide.

The only thing mentioned above that's Hobo specific is lifecycles.
This is a data modeling question.   Can anybody point Archfile X at a
good data modeling book or tutorial?

thanks,
Bryan

On Oct 23, 7:52 pm, Archfile X <[email protected]> wrote:
> Hi all, I've been using hobo for a little while, hardly a hobo-ninja
> but getting by, I have a business logic -> hobo issue that I am sure
> is easy to do, but hard to describe.
>
> say for example I have:
>
> customer
>   -> order
>         -> many cupcakes
>
> cupcake
>     -> one mixture
>           -> many ingredients
>
> order_associat
>    -> order <-> cupcake
>
> ingredient
>     -> stock_level
>     -> cost etc...
>
> If I want to create a new cupcake mixture, and i want each instance of
> that cupcake that is added to an order to deplete the stock level, how
> do i do that, I have all the mechanics covered other than the auto
> depletion of the stock level based on the orders.. making the records
> and assigning cupcakes to an order and mixes to cupcakes etc..
>
> I'm sure its not a hard thing to do, but I'm missing something in my
> understanding on how this works, this isn't homework or something, its
> a simplification of a problem that i don't understand -- hopefully I
> make some sense writing it.
>
> thanks for any advice that can be given, I'm so impressed with hobo
> that i'd be happy to write the cupcake example up as a tutorial when i
> get it working too, perhaps others have had the same gap in
> understanding
>
> cheers
> Arch
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to