[Nitro] Og deep copy?

Jos Backus jos at catnook.com
Wed Dec 7 15:08:34 EST 2005


Say I have an application with order, order_line and item. order has one or
more order_lines, and each order_line has one item. order_line refers to order
and item, and is a dependent of order and item.

Now say I have this requirement where I want to be able to create a new order
with all its order_lines based on an existing order, where the existing order
functions as a template. In this case I would want to copy the order plus all
its dependents (and their dependents, if any). Since order_lines are
dependents of orders I'd want to copy them, but not their associated items
since order_lines are dependents of items, not the other way around.

                /--------\
                | order1 |
                \--------/         /------\
                     \             | item |
                      \            \------/
                       \              /  \
                       1:n           /    \
                         \         1:1     |
                          \        /       |
                           v      v        |
                        /-------------\    |
                        | order_line1 |\   |
                        \-------------/|   |
                         \-------------/   |
                                           |
                               |           |
                       copy -> |           |
                               V           |
                                           |
                /--------\                 |
                | order2 |                /
                \--------/               /
                     \                  /
                      \                /
                       \              /
                       1:n           /
                         \         1:1
                          \        /
                           v      v
                        /-------------\
                        | order_line1 |\
                        \-------------/|
                         \-------------/

Iow, I'm looking for a general way to do this type of selective deep copy
using Og, exploiting Og's knowledge of the relationships between the objects.
How would one go about doing this?

-- 
Jos Backus
jos at catnook.com



More information about the Nitro-general mailing list