0
votes

I am implementing a Google App Engine based Web Application. The app uses ndb and there are two entities (say A and B) with a one to many relationship implemented via this property in the A class model

 bObjects = ndb.KeyProperty(repeated=True);

I have an instance of A (a1) in relationship with three instance of B (b1,b2,b3) I am trying to delete b2. To this end I am trying to remove it from the relationship with a1 in this way

  a1.bObjects.remove(b2.key)

the command is executed but the element is not removed. What am I doing wrong?

1
Just to be clear since you don't show it in your example. Are you doing a1.put() after a1.bObjects.remove(b2.key)?Mihail Russu
great! I always have to put it! thank you!lowcoupling
awesome, I'll make it an answer then.Mihail Russu
the fact I was actually getting a1 from b2 like b2.aObject.get().bObjects.remove(b2.key) and I was not realizing I also had to do b2.aObject.get().put()lowcoupling

1 Answers

3
votes

As indicated in the comments above you always need to call put() method to save and send the changes back to the Datastore.

In your example the proper code to save the changes would be:

  a1.bObjects.remove(b2.key)
  a1.put()