Google App Engine のリレーショナル データベースを再構築しようとしていますが、必要なデータを効率的にクエリできるように一連の関係をモデル化することに問題があります。
不自然な例として、次のモデルがあるとします。
class Rental(db.Model):
# ancestor of one or more RentalDatas
date = db.DateProperty()
location = db.IntegerProperty()
# + customer, etc
class RentalData(db.Model):
# a Rental is our parent
unicorn = db.ReferenceProperty(Unicorn, collection_name='rentals')
mileage_in = db.FloatProperty()
mileage_out = db.FloatProperty()
# + returned_fed, etc
class Unicorn(db.Model):
name = db.StringProperty()
color = db.IntegerProperty()
# 'rentals' collection from RentalData
各レンタルには複数のユニコーンが含まれている可能性があるため、できればRental
とモデルを組み合わせたくありません。RentalData
私はほとんどの場合、指定された から始めUnicorn
ます。たとえば、ユニコーンRentalData
のrentals
コレクション内のすべてを反復処理して、親、ソートする日付を取得するだけです。
弾丸を噛んで非正規化する必要がありますか? で複製date
しRentalData
、必要に応じてparent()を使用して、Rental
プロパティが必要なときに対応するものを取得しようとしました。うまくいきますが、簡単な方法を取っているだけではないかと心配しています。