Hi all. Possibly a real basic question but one I seem to have gone
round in circles with and failed to find an answer for so far.

I have an (Oracle) db with some tables similar to this. I'll create a
simple in-memory sqlite db just to illustrate.


    from sqlalchemy import *

db = create_engine('sqlite://')
metadata = MetaData(db)
account_ids_table = Table('account_ids', metadata,
        Column('account_id', Integer, primary_key=True),
        Column('username', String(20)))
account_stuff_table = Table('account_stuff', metadata,
        Column('account_id', Integer,
ForeignKey('account_ids.account_id')),
        Column('credit', Numeric))
metadata.create_all()

# Load up a couple of rows.
account_ids_table.insert().execute(
        {'account_id': 1, 'username': 'andyh'},
        {'account_id': 2, 'username': 'richo'})
account_stuff_table.insert().execute(
        {'account_id': 1, 'credit': 0},
        {'account_id': 2, 'credit': 100.5})

# Okay. Now create a session, something to map to and join
class Account(object):
    pass

# Create a mapper based on the two tables just joined via account_ids
mapper(Account, join(account_ids_table, account_stuff_table))
session = create_session()
ac = session.query(Account).filter_by(account_id=1).first()

# And then modify and get an error...
ac.credit = 10
session.flush()


When the flush executes I get the error:
<class 'sqlalchemy.exceptions.ConcurrentModificationError'>: Updated
rowcount 2 does not match number of objects updated 1

because it's trying to execute the sql: UPDATE account_stuff SET
credit=?

because I assume account_stuff has no primary key (updates to
account_ids specify a where clause).

How can I get the above to work? I assume the join in the mapper needs
to specify something else? Is it possible?

Thanks
Andy Hird


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