I run into some problems trying to create entities using this structure:
class MainEnt(ndb.Model):
name = ndb.StringProperty()
choices = ndb.KeyProperty(repated=True)
@classmethod
@ndb.transactional
def create(cls, name, choices):
#Here comes my problem!
class Choice(ndb.Model):
name = ndb.StringProperty()
So here I have a main entity that haves a list of some choices. To create the main entity I need to use a transaction to consistently create the main entity and the choices entities. If some operation fail I want all to fail.
The problem is that to run inside a transaction all need to be in the same entity group but I can't do that because I don't know the key of the main entity to assign it as the parent argument to each choice. I can't use allocate_ids inside a transaction so this option doesn't work.
I don't want to use Cross-Group transactions, and also don't want to save the main entity two times.
Also I was considering using queries to fetch the choices and don't use the repeated property, but as long as I will usually only have 2-3 choices per MainEnt, using queries is a waste of resources.
What can I do?
create
factory so we can see what you are really up to. – Tim Hoffman