0

私は App Engine のデータストアのこの機能に出くわしました。それは、GAE で動作の一貫性を保つために永続化されたルート エンティティを実際に持つ必要がないということです。計算されたキーを使用して、子エンティティを格納およびロードできます。私の質問は次のとおりです。これは良い習慣ですか、それともデータストアの実装の癖に頼りすぎていますか?

Python を使用した例を次に示します。この慣用句は Java でも機能するはずです。

子エンティティがあるとしましょう:

CustomerReport(ndb.Model):
  foo=ndb.StringProperty
  bar=ndb.FloatProperty
  #...

CustomerReports は、実際のエンティティ タイプ Customer に基づいて生成されます。ただし、次のように存在しない親エンティティの祖先キーを計算することで、このレポート エンティティを強い整合性で保存できます。

ReportRoot(ndb.Model):
  pass

そのようです:

CustomerReport(parent=ndb.Key(ReportRoot, customer.key.id()), ... ).put()

これは、キーを計算するだけで再度取得できます。

CustomerReport.query(ancestor=ndb.Key(ReportRoot, customer.key.id())).fetch()

ありがとうございました。

4

1 に答える 1

2

Using a key as a parent that doesn't have a corresponding saved entity is perfectly fine. You don't even need to create a python class, just use the name as a string:

parent=ndb.Key('ReportRoot', some_id)

Your example, though, seems confused. What do you think you're gaining over just using the Customer's key as the Reports' parents?

于 2014-09-01T19:33:06.803 に答える