With the following simplified setup I receive the following error:

FlushError: instance <erp.model.financial.TransactionOffset object at
0x0203CC90> is an unsaved, pending instance and is an orphan (is not
attached to any parent 'Transaction' instance via that classes'
'offsets' attribute)

When attempting something along the lines of

transactions = Transaction.query.all()
offset = TransactionOffset()
offset.transaction = transactions[4]
offset.offset_transaction = transactions[5]
meta.Session.commit()

However, if I append offset to transactions[4].offsets it will save
transaction_id, but not offset_transaction_id

Classes:
class Transaction(Entity):
    pass

class TransactionOffset(Entity):
    pass

Tables:

transactions = Table('transactions', meta,
    Column('id', Integer, primary_key=True),
    Column('date', Date),
    Column('description', Text),
    Column('amount', Float),
    Column('transaction_code', String(50)),
    Column('approval_code', String(50)),
    Column('voided_at', DateTime),
)

transaction_offsets = Table('transaction_offsets', meta,
    Column('id', Integer, primary_key=True),
    Column('amount', Float),
    Column('transaction_id', Integer),
    Column('offset_transaction_id', Integer),
    ForeignKeyConstraint(['transaction_id'], ['transactions.id']),
    ForeignKeyConstraint(['offset_transaction_id'],
['transactions.id']),
)

Mappers:

transactions_mapper = mapper(Transaction, transactions, properties={
            'offsets': relation(TransactionOffset,
primaryjoin=transaction_offsets.c.transaction_id==transactions.c.id,
cascade='all, delete-
orphan'),
})

mapper(TransactionOffset, transaction_offsets, properties={
        'transaction': relation(Transaction,
primaryjoin=transaction_offsets.c.transaction_id==transactions.c.id,
post_update=True),
        'offset_transaction': relation(Transaction,
primaryjoin=transaction_offsets.c.offset_transaction_id==transactions.c.id,
post_update=True),
})

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

Reply via email to