On Mar 21, 2008, at 8:41 PM, Gary Poster wrote:

On Mar 20, 2008, at 11:04 PM, Sean Allen wrote:

I've been playing with this and I'm still having a disconnect 3 week later.

1. I love the zc.relation stuff it answers one area of stuff I hadn't even gotten to yet.

cool :-)

2. I'm just totally missing something

less cool. :-/

If I have Customers and Orders and I want to be able update all of them independently of their relationships ( so that if an order is updated, when i get the customer at some later time, it has the updated order amongst that relation ) but I can't figure it out. I tried looking at the zope.app.folder stuff but I keep getting lost in the zope aspects of it and am having a hard time seeing the forest for the trees.

Is there some more general ready on the patterns used that you know of? I think if I understood the idea more in an abstract sense, I could get a lot more out of the folder implementation.

Here's a simple, dumb example that parallels the folder stuff. See the Dict class in http://svn.zope.org/zc.async/branches/dev/src/zc/async/utils.py?rev=84657&view=auto . You put something in the dict, and __setitem__ slams a name and a parent. The other mutating methods should do the right thing as well in terms of updating the back reference. So, completely randomly and arbitrarily, but to try and make a parallel, what if customers were a dict of orders, and when you made an order it was associated with only one customer, and you put the order "in" the customer. This may be bizarre--what's the key? can more than one customer be associated with an order? But that would mean that customer.values() would get all of the customer's orders, and order.parent would be the associated customer.

This example subclasses zc.dict, a super simple package that only depends on ZODB, btw. It does not have full dict behavior, as Jim likes to point out, because items are stored by BTree sorting, not hashes, but it looks like a dict otherwise. Maybe it can help you out. If you want to try out this example, copy the code out and get the zc.dict egg and give it a try.

Ok, I can see how this makes sense for the simple example I gave. You can get all the info you need for any contained items by starting from the customer. That part I was already seeing but hadnt fully put it together because I was distracted by the bigger complication part that keeps my brain churning.

Let me give a more detailed example of where I hit a problem ( I'm still leaving some stuff out, just trying to get the general map of things here ):

   has many addresses
   has many orders
   has many paymethods

   has many items
   belongs to customer

    has a product
    belongs to order


In this example if we have 3 Products w/ skus of:

Widget A

Widget B

Widget C

And we want to change the the description of Widget B and have that change appear for everything, how do I do that? basically, I want all LineItems for Widget A to all refer to a single instance of Product. In a relational database, that is easy... there are 3 entries in the Products table and there is a foreign key in LineItems. Here, I have no idea how
to handle. Which makes me think that I'm missing some fundamental point.

I'm sure the answer to this will start a whole slew of new questions, so thanks in advance for the help with this and going forward. Its very frustrating to keep beating my head against these conceptual points that I'm just not getting. Usually, I have eureka moments after spending this much time on something, this time, its just not coming.

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to