了解GAE中的ListProperty后端行为

Yar*_*rin 6 google-app-engine google-cloud-datastore

我试图了解你应该如何访问GAE db.ListProperty(db.Key)中的项目.

例:

一个Magazinedb.Model实体有db.ListProperty(db.Key),其中包含10 Article元.我想获取Magazine对象并显示文章名称和日期.我是否对实际的文章对象进行了10次查询?我是否进行批量查询?如果有50篇文章怎么办?(批处理查询是否依赖于IN运算符,该运算符限制为30个或更少的元素?)

Kev*_*n P 7

所以你描述的是这样的:

class Magazine(db.Model):   
    ArticleList = db.ListProperty(db.Key)

class Article(db.Model):
    ArticleName = db.StringProperty()
    ArticleDate = db.DateProperty()
Run Code Online (Sandbox Code Playgroud)

在这种情况下,获取列出文章的最简单方法是使用Model.get()方法,该方法查找键列表.

m = Magazine.get() #grab the first record

articles = Article.get(m.ArticleList) #get Articles using key list

for a in articles:
    name = a.ArticleName
    date = a.ArticleDate
    #do something with this data
Run Code Online (Sandbox Code Playgroud)

根据您计划使用数据的方式,您可能最好将"杂志"引用属性添加到文章实体中.