user2667409
user2667409

Reputation: 1219

GOOGLE APP ENGINE - NDB - KEY

I have table A and AEXT.

I would like to use the same KEY/ID for AEXT as the relationship between table A and table AEXT are 1-1 and as the name suggests AEXT has extended/additional attributes of A.

Can someone please let me know how can I do this in NDB/Python.

Thanks in advance

Upvotes: 1

Views: 179

Answers (1)

William Gaul
William Gaul

Reputation: 3181

Two "tables" (really entity types) can have the same key name as long as they have different paths in the datastore. A path is the kind/name of the entity and all of its ancestors. So for example you could do:

a_key = ndb.Key(A, 'mykey')
aext_key = ndb.Key(AEXT, 'mykey')

Now these keys would be different, but you could construct them again using the same key name, 'mykey'. And once you have the keys, you can grab the entities themselves.

Hope that helps!

Upvotes: 2

Related Questions