Yeah, I tried that! But still I get a: AttributeError: ("type object 'Supplier' has no attribute 'supplier'",) Same with the example in the docs (but then for article)! I have included a ready-to-run testscript. |
from sqlalchemy import * engine = create_engine('sqlite:///::memory::', echo=True)
metadata = MetaData() products = Table('products', metadata, Column('id', Integer, Sequence('products_id_seq',optional=False), primary_key=True), Column('name', Unicode(255), nullable=False), Column('price', Numeric, nullable=False), ) suppliers = Table('suppliers', metadata, Column('id', Integer, Sequence('suppliers_id_seq',optional=False), primary_key=True), Column('name', Unicode(255), nullable=False) ) product_suppliers = Table('product_suppliers', metadata, Column('product_id', Integer, ForeignKey("products.id")), Column('supplier_id', Integer, ForeignKey("suppliers.id")), Column('price', Numeric, nullable=False), Column('precedence', Integer, nullable=False) ) class Product(object): def __init__(self, name, price): self.name = unicode(name) self.price = price class ProductAssociation(object): pass class Supplier(object): def __init__(self, name): self.name = unicode(name) mapper(Supplier, suppliers) mapper(ProductAssociation, product_suppliers, primary_key = [product_suppliers.c.product_id, product_suppliers.c.supplier_id], properties = { 'supplier':relation(Supplier) } ) mapper(Product, products, properties={ 'suppliers': relation(ProductAssociation, lazy=False, cascade="all, delete-orphan", association=Supplier) }) # Recreate all tables for testing purposes engine.echo = False metadata.drop_all(engine=engine) metadata.create_all(engine=engine) engine.echo = True session = create_session(bind_to=engine) product = Product(name='MacBook', price='100') supplier1 = Supplier('Apple') supplier2 = Supplier('Unit 4') product.suppliers.append(supplier1) product.suppliers.append(supplier2) session.save(product) session.flush()
On May 28, 2006, at 6:37 PM, Michael Bayer wrote: yah no prob, you just need this: |
smime.p7s
Description: S/MIME cryptographic signature