Manage nested list of entities within entities in Google Cloud Datastore

江枫思渺然 提交于 2019-12-01 21:54:25

In general this is not a scalable approach: every time a user borrows a book you'd have to re-write both the user and book entities, which will get progressively slower as both entities will keep growing.

I'd suggest a different approach: add a new type to your schema, let's call it borrowed_book, representing a book boorowed by a user:

borrowed_book:
  book_id
  user_id
  timestamp

Now every time a user borrows a book you'd simply create one such borrowed_book entity, pointing to both the book and the user. No changes to the user or the book entities. And no nesting required.

Side note: I'd place the firstname and email properties under the user entity type, they don't really belong to the borrowing event where they would be duplicated every time such event occurs for the same user.

Also try to not get confused by the ancestry - it is not required for establishing relationships, see E-commerce Product Categories in Google App Engine (Python)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!