Understanding BackProperty Behavior in GAE

I am trying to understand how you should access elements in GAE db.ListProperty (db.Key).

Example:

A Magazine db.Model entity has a db.ListProperty (db.Key) that contains 10 Article entities. I want to get a Magazine object and display the names and dates in the article. Am I making 10 queries for real article objects? Am I doing a batch request? What if there are 50 articles? (Do not execute queries in batch mode with an IN statement that is limited to 30 or less elements ?)

+6
source share
2 answers

So you are describing something like this:

 class Magazine(db.Model): ArticleList = db.ListProperty(db.Key) class Article(db.Model): ArticleName = db.StringProperty() ArticleDate = db.DateProperty() 

In this case, the easiest way to capture the listed articles is to use the Model.get () method, which searches for a list of keys.

 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 

Depending on how you plan to work with the data, you might be better off adding a link property to the log for your Article objects instead.

+7
source

You need to read Modeling Entity Relationships , especially the one-to-many part.

-2
source

Source: https://habr.com/ru/post/902037/


All Articles