Hi,

I feel really stupid having to ask about this, but now I've searched wide 
and far for an answer and haven't found one.  

To make the problem clear and easily repeatable, I've mapped my problem to 
a simplified scenario where I've followed the installation example on 
http://turbogears.org/ and created the "example" app.

My problem is that I have some many-to-many relationships in my data model, 
modeled just like the user_group_table in example.model.auth.  Now, I want 
to be able to delete a row in that table by using just the primary/foreign 
keys.  However, the changes aren't committed.  The following test script 
should explain my problem:

# -*- coding: utf-8 -*-

from example.model import DBSession
from example.model.auth import User, user_group_table
from sqlalchemy import and_
import transaction

def delete_test():
    DBSession.query(user_group_table).all()
    # [(1, 1)]

    d = user_group_table.delete(
        and_(user_group_table.c.user_id == 1, 
             user_group_table.c.group_id == 1))
    DBSession.execute(d)
    DBSession.flush()
    transaction.commit()

    DBSession.query(user_group_table).all()
    # [(1, 1)]

if __name__ == '__main__':
    delete_test()

When I try to run this inside a "paster shell development.ini", the 
SQLAlchemy log even reports:
>>> DBSession.execute(d)
17:31:15,903 INFO  [sqlalchemy.engine.base.Engine] DELETE FROM 
tg_user_group WHERE tg_user_group.user_id = ? AND tg_user_group.group_id = ?
17:31:15,903 INFO  [sqlalchemy.engine.base.Engine] (1, 1)

And, just to make sure, I can assert that I have no similar problems when 
doing SQLAlchemy operations on ORM-mapped instances.

As I tried to explain above, my problem is not with the user_group_table, 
but (in my case) a much larger, app-specific table.  Any help will be 
highly appreciated.

Furthermore, my real application uses MySQL (in production) and PostgreSQL 
(upcoming development) back-ends, but the problem seemed to be repeatable 
even with the default sqlite back-end.


-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to