pythonsqlalchemypython-elixir

Elixir EntityCollection.remove() doesn't work


I'm trying to remove a certain Entity from the collection in a EntityCollection, which is not working, results in an exception: list.remove(x): x not in list.

Code excerpt as follows:

user.platformSubscriptions.remove(platform)

The platform variable is in fact in the platformSubscriptions collection.


Solution

  • The reason it didn't work was probably because there was no proper comparator function for the platform object. So the solution is to loop through platformSubscriptions to find a match for platform by comparing the id field:

    for subedPlat in user.platformSubscriptions:
        if subedPlat.id == platform.user.platformSubscriptions.remove(subedPlat)