[sqlalchemy] Re: Unknown inheritance type question
this mapping: transaction_sale_join = join(transactions, sales) mapper(Sale, transaction_sale_join, inherits=transactions_mapper, polymorphic_identity=3, properties={ 'line_items': relation(LineItem, backref='sale', cascade='all, delete-orphan') }) is incorrect. The inherits configuration will create the join from transactions-sales for you - Sale should be mapped directly to sales. On Jun 4, 2008, at 6:29 PM, Brad Wells wrote: The complexity of the following setup is that of the transaction type Sales also have their own table. I am unsure of how properly establish this relationship between Transactions, Sales and TransactionTypes. This setup so far allows me to create Sale objects and save them. However Sale.query.all() (for example) results in: OperationalError: (OperationalError) (1066, Not unique table/alias: 'transactions') any advice is appreciated. Tables: transactions = Table('transactions', meta, Column('id', Integer, primary_key=True), Column('transaction_type_id', Integer), ForeignKeyConstraint(['transaction_type_id'], ['transaction_types.id']), ) transaction_types = Table('transaction_types', meta, Column('id', Integer, primary_key=True), Column('name', String(15)), Column('has_line_items', Boolean), ) sales = Table('sales', meta, Column('id', Integer, primary_key=True), Column('address', Text), Column('shipping', Float), Column('handling', Float), Column('purchase_order', String(35)), Column('transaction_id', Integer), ForeignKeyConstraint(['transaction_id'], ['transactions.id']), ) line_items = Table('line_items', meta, Column('id', Integer, primary_key=True), Column('position', Integer), Column('description', Text), Column('quantity', Float), Column('units', String(15)), Column('unit_rate', Float), Column('tax', Float), Column('transaction_id', Integer), ForeignKeyConstraint(['transaction_id'], ['transactions.id']), ) Classes: class Transaction(Entity): pass class TransactionType(Entity): pass class Payment(Transaction): pass class Adjustment(Transaction): pass class Receipt(Transaction): pass # abstract class class LineItemTransaction(Transaction): pass class Cost(LineItemTransaction): pass class Sale(LineItemTransaction): pass class LineItem(Entity): pass Mappers: mapper(TransactionType, transaction_types) transactions_mapper = mapper(Transaction, transactions, polymorphic_on=transactions.c.transaction_type_id, polymorphic_identity=0, properties={ 'transaction_type': relation(TransactionType, backref='transactions'), }) mapper(Cost, inherits=transactions_mapper, polymorphic_identity=1, properties={ 'line_items': relation(LineItem, backref='cost', cascade='all, delete-orphan') }) mapper(Payment, inherits=transactions_mapper, polymorphic_identity=2) mapper(Receipt, inherits=transactions_mapper, polymorphic_identity=4) mapper(Adjustment, inherits=transactions_mapper, polymorphic_identity=5) transaction_sale_join = join(transactions, sales) mapper(Sale, transaction_sale_join, inherits=transactions_mapper, polymorphic_identity=3, properties={ 'line_items': relation(LineItem, backref='sale', cascade='all, delete-orphan') }) mapper(LineItem, line_items) -brad --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Unknown inheritance type question
Thank you very much. again. -brad On Jun 5, 10:57 am, Michael Bayer [EMAIL PROTECTED] wrote: this mapping: transaction_sale_join = join(transactions, sales) mapper(Sale, transaction_sale_join, inherits=transactions_mapper, polymorphic_identity=3, properties={ 'line_items': relation(LineItem, backref='sale', cascade='all, delete-orphan') }) is incorrect. The inherits configuration will create the join from transactions-sales for you - Sale should be mapped directly to sales. On Jun 4, 2008, at 6:29 PM, Brad Wells wrote: The complexity of the following setup is that of the transaction type Sales also have their own table. I am unsure of how properly establish this relationship between Transactions, Sales and TransactionTypes. This setup so far allows me to create Sale objects and save them. However Sale.query.all() (for example) results in: OperationalError: (OperationalError) (1066, Not unique table/alias: 'transactions') any advice is appreciated. Tables: transactions = Table('transactions', meta, Column('id', Integer, primary_key=True), Column('transaction_type_id', Integer), ForeignKeyConstraint(['transaction_type_id'], ['transaction_types.id']), ) transaction_types = Table('transaction_types', meta, Column('id', Integer, primary_key=True), Column('name', String(15)), Column('has_line_items', Boolean), ) sales = Table('sales', meta, Column('id', Integer, primary_key=True), Column('address', Text), Column('shipping', Float), Column('handling', Float), Column('purchase_order', String(35)), Column('transaction_id', Integer), ForeignKeyConstraint(['transaction_id'], ['transactions.id']), ) line_items = Table('line_items', meta, Column('id', Integer, primary_key=True), Column('position', Integer), Column('description', Text), Column('quantity', Float), Column('units', String(15)), Column('unit_rate', Float), Column('tax', Float), Column('transaction_id', Integer), ForeignKeyConstraint(['transaction_id'], ['transactions.id']), ) Classes: class Transaction(Entity): pass class TransactionType(Entity): pass class Payment(Transaction): pass class Adjustment(Transaction): pass class Receipt(Transaction): pass # abstract class class LineItemTransaction(Transaction): pass class Cost(LineItemTransaction): pass class Sale(LineItemTransaction): pass class LineItem(Entity): pass Mappers: mapper(TransactionType, transaction_types) transactions_mapper = mapper(Transaction, transactions, polymorphic_on=transactions.c.transaction_type_id, polymorphic_identity=0, properties={ 'transaction_type': relation(TransactionType, backref='transactions'), }) mapper(Cost, inherits=transactions_mapper, polymorphic_identity=1, properties={ 'line_items': relation(LineItem, backref='cost', cascade='all, delete-orphan') }) mapper(Payment, inherits=transactions_mapper, polymorphic_identity=2) mapper(Receipt, inherits=transactions_mapper, polymorphic_identity=4) mapper(Adjustment, inherits=transactions_mapper, polymorphic_identity=5) transaction_sale_join = join(transactions, sales) mapper(Sale, transaction_sale_join, inherits=transactions_mapper, polymorphic_identity=3, properties={ 'line_items': relation(LineItem, backref='sale', cascade='all, delete-orphan') }) mapper(LineItem, line_items) -brad --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---