Elixir EntityCollection.remove() doesn't work

158 Views Asked by At

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.

1

There are 1 best solutions below

0
ronalddddd On BEST ANSWER

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)