I've tried to find something similar in the SA 0.3 docs but haven't
managed yet. They are dense though so I could easily have missed
something. Apologies if this seems a simple problem! :/

I have a product table, some are allowed to be collections ( ie gift
basket. ) They will have children, which are in turn products. I put in
a boolean attribute so I can control whether they are collections, and I
only need one layer deep, so products can be collections or children,
and not both. Each product can be the child of many collections.

I was hoping I could handle this by having a many to many table of
parent products to children so I could do:
collection.children

Below is what I have tried and failed with:

# many to many of collection-products to products
collections_products_table = Table('collections_products', metadata,
    Column('collection_id', Integer, ForeignKey('products.id') ),
    Column('product_id', Integer, ForeignKey('products.id') ),
    )

#mapper
assign_mapper(session.context, Product, product_table, properties={
'children': relation( Product, secondary=collections_products_table, 
lazy=True, )
})


or 
assign_mapper(session.context, Product, product_table, properties={
'children': relation( Product, secondary=collections_products_table, 
primaryjoin =
collections_products_table.c.collection_id==product_table.c.id,
lazy=True ),
})


Neither of the above work. Tg loads ok but when I try to make a product
I get the following:

ArgumentError: Error determining primary and/or secondary join for
relationship 'children' between mappers 'Mapper|Product|products' and
'Mapper|Product|products'.  If the underlying error cannot be corrected,
you should specify the 'primaryjoin' (and 'secondaryjoin', if there is
an association table present) keyword arguments to the relation()
function (or for backrefs, by specifying the backref using the backref()
function with keyword arguments) to explicitly specify the join
conditions.  Nested error is "Cant determine join between 'products' and
'collections_products'; tables have more than one foreign key constraint
relationship between them.  Please specify the 'onclause' of this join
explicitly."

I'm in over my head here, so if anyone has the time to comment on the
above that would be luverly.

Thanks
Iain



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to