using relationship() with collection_class=set, assuming User, User.preferences 
-> Pref, just assigning to the collection will replace the previous contents 
with the new one:

myuser.preferences = set([Pref("A"), Pref("C")])

B and D go into the "removed" list, A and C are "pending", on flush you'll see 
the rows managed.  If User->Pref is one-to-many, that is Pref is "owned" by 
just one user, use cascade="all, delete-orphan" - Pref B and D will be deleted 
on flush.   

On Apr 2, 2012, at 7:32 AM, Franck wrote:

> Hi,
> 
> To store the preferences of my users I'm storing one row per user &
> per preference : if the possible choices are A,B,C,D I'm storing B,C,D
> for instance at the user level in the database.
> Suppose the user changes its preferences and picks A,C for instance.
> 
>> I'm going to need to delete B & D
>> I'm going to need to persist A
> 
> I was thinking to do this manually with the builtin set operations
> (http://docs.python.org/library/stdtypes.html#set), typically
> "difference", to manually add/remove these in the session but is there
> a way SQLAlchemy can do the work for me automatically ?
> 
> Thanks !
> Franck
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> 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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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