Mazyod
Mazyod

Reputation: 22559

GAE: Creating a a child entity automatically

In the GAE application I am developing, I have a Room entity, which has a KeyProperty to a Match object. The room should always have a match, and that match can't exist without the room.

Now, I am assuming that I have to create a match object like this:

Match(parent=room.key)

But, the room always requires a match to be created, and the only way I can think of doing this is as follows:

room = Room()
match = Match(parent=room.put())
room.match_key = match.put()
room.put() # again!

Is there a way to avoid this problem?

Upvotes: 0

Views: 50

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599480

I don't see why you want both the Match to have the Room as a parent, and the parent to have a KeyProperty to the Match. This is unnecessarily circular. Choose one or the other: if you want a parent/child relationship, keep the parent key and query the Match via ancestor(); otherwise leave out the parent key, so no need to create the Room first.

Upvotes: 5

Related Questions