views:

21

answers:

1

There is a m2m relation in my models, User and Role.

I want to merge a role, but i DO NOT want this merge has any effect on user and role relation-ship. Unfortunately, for some complicate reason, role.users if not empty.

I tried to set role.users = None, but SA complains None is not a list.

At this moment, I use sqlalchemy.orm.attributes.del_attribute, but I don't know if it's provided for this purpose.

A: 

You'd better fix your code to avoid setting role.users for the item you are going to merge. But there is another way - setting cascade='none' for this relation. Then you lose an ability to save relationship from Role side, you'll have to save User with roles attribute set.

Denis Otkidach