user1055761
user1055761

Reputation: 1071

Will Datastore fetch Reference'd Entity if already fetched?

class Author (db.Model)
   name = db.StringProperty()

class Book (db.Model)
   author = db.ReferenceProperty (collection_name="books", indexed=True)
   name = db.StringProperty()

author = Author.get (author_key)
q = Book.all()
q.filter ("author =", author.key())
q.filter ("name =", "BOOK_NAME")
book = q.fetch(1)[0]

book.author.name

Will the last statement (book.author.name) result in a another read on datastore?

Upvotes: 0

Views: 45

Answers (1)

Tim Hoffman
Tim Hoffman

Reputation: 12986

Yes

If you are just starting out consider using ndb, which has cacheing of get requests built in.

Upvotes: 2

Related Questions