On Wed, Mar 4, 2009 at 17:43, Enrico Morelli <[email protected]> wrote: > > Dear all, > > I'm using Elixir 0.5.2 with CherryPy 3 with the following model: > > class Users(Entity): > id = Field(Integer, primary_key=True) > firstname = Field(String(30)) > lastname = Field(String(30)) > logname = Field(String(15)) > password = Field(String(35)) > email = Field(String(30)) > privilege = Field(String(1)) > supervisor = Field(Boolean) > admin = ManyToMany('Users') > > Using the following code I'm able to add one or more admin to each user > and remove more admin at the same time but if I try to remove only > one admin I receive "SQLError: list.remove(x): x not in list" but the > relation is removed!!. (data is a dictionary with the fields values > coming from a form. data['newRight'] can contains the ids of users that > has supervisor field=True and that I want to associate with the user, > data['removedRight'] can contains the ids of user supervisors that I > want to remove from the user). > > if data['newRight']: > super_ids=data['newRight'].split(',') > u.admin=[] > for s_id in super_ids: > if s_id: > admin = Users.query.get(s_id) > u.admin.append(admin) > u.update() > if data['removedRight']: > super_ids=data['removedRight'].split(',') > for s_id in super_ids: > if s_id: > adm = Users.query.get(s_id) > u.admin.remove(adm) > u.update() > session.flush() > > > Someone can explain me where I wrong?
At first glance your code seems ok. I fear you are simply using bad data (ie trying to remove a relation which doesn't exist). The problem *might* come from session.flush()... Are you using an autocommit session? Try to turn on echo on your engine to see what happens behind the scene. Probably unrelated, but I wonder what u.update() is. -- Gaëtan de Menten http://openhex.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SQLElixir" 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/sqlelixir?hl=en -~----------~----~----~----~------~----~------~--~---
