0

I'm trying to save a datastore entity reference within another:

class Save(webapp2.RequestHandler):

    def get(self):

        order = Order(parent=ndb.Key('Orders', 'default_orders'))

        order.special_request     = self.request.get('specialRequirement')
        order.product_type        = self.request.get('productType')

        customer = Customer(parent=ndb.Key('Customer', 'default_customers'))

        customer.name              = self.request.get('customerName')
        customer.email             = self.request.get('email')
        customer.put()

        order.customer             = customer
        order.put()

The Customer class is simply:

from google.appengine.ext import ndb

class Customer(ndb.Model):
    name    = ndb.StringProperty()
    email   = ndb.StringProperty()

Whilst I've done similar with Rails and mongodb before, I'm not sure what this is called in GAE and am having a hard time searching for examples.

4

1 回答 1

0

好的,以下似乎是我的疏忽,只需将密钥传递为:

oder.customer           = customer.key

我现在有一个对嵌入对象的可用引用,并且两者都被正确保存。

于 2013-05-26T19:34:02.153 回答