-1

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.

Ben
  • 51,770
  • 36
  • 127
  • 149
ronalddddd
  • 111
  • 2
  • 8
  • `platform` must not be in the `platformSubscriptions` collection. Please post a stack trace and additional code that will allow us to help you. – wberry Nov 18 '11 at 18:17
  • @wberry thanks, indeed you are correct, but more specifically they are not of the same **instance** even though the objects are from the same record. Hence the default comparator would not find a match in the list. – ronalddddd Nov 18 '11 at 23:45

1 Answers1

0

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)
ronalddddd
  • 111
  • 2
  • 8