On Fri, 2008-03-21 at 22:49 -0400, Sean Allen wrote:
> 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.

If you simply assign the product to an attribute on the line item, it
will create a reference in the ZODB. And you can use zc.relation to
index and query the relation.

# get the product from your products container:
product = productfolder['ProductXYZ']
# assign it to the line item instance
lineitem.product = product

It's really that simple! If you change the description attribute of the
referenced product, all line items referencing it will show the new
description.

>  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.

This is what zc.relation is for. On your line item instance, you assign
to a attribute that holds the product reference and you use zc.relation
to index and query it.

> 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.

Don't worry you'll get it soon :-) ZODB programming is easier than
people expect so they don't easily accept it ;-)

Stepping back somewhat, I'll structure the app like this. Have
containers in the root of your app for customers and products. Store
customers in your customer container, orders inside the customer and
line items in the order:

Customers
    |
    +--- Customer
            |
            +----- Order
                     |
                     +--- Line item

Products
    |
    +---- Product

Hope that helps.

-- 
Roché Compaan
Upfront Systems                   http://www.upfrontsystems.co.za

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to