title: Manage nested list of entities within entities in Google Cloud Datastore
body: <p>I am new to Datastore and I am trying to create a simple app that tracks books borrowing.</p>
  
  <p>I would like the DB schema to be as follows:</p>
  
  <pre><code>books:
   book_id
    name:
    borrowing:
     timestamp:
      user_id
      firstname
      email
  
  users:
   name:
   borrowed:
    timestamp:
     book_id
  </code></pre>
  
  <p>I am using the console to configure the DB.</p>
  
  <p>I have defined two Kinds: <code>Books</code> and <code>User</code></p>
  
  <p>Business logic:</p>
  
  <ul>
  <li>1 book can be borrowed by n users.</li>
  <li>1 user can borrow n books</li>
  </ul>
  
  <p>Basically, when a user borrows a book I want the two following inserts to occur:</p>
  
  <ul>
  <li>a new borrowing entry is appended to the book entity of type Book, with the current timestamp as key and user_id, firstname and email as properties</li>
  <li>a new borrowed entry is appended to the user entity of ty User, with the current timestamp as key and the book_id as property</li>
  </ul>
  
  <p>How can I achieve this (managing nested lists children) with Datastore? Through embedded entities? Parent ref?</p>
  
  <p>Here is an example of what I expect:</p>
  
  <pre><code>{
    "books": {
        "book1": {
            "name": "book number 1",
            "borrowing": {
                "1234567890": {
                    "user_id": "user1",
                    "firstname": "john",
                    "email": "john@example.com"
                },
                "2234567890": {
                    "user_id": "user2",
                    "firstname": "robin",
                    "email": "robin@example.com"
                }
            }
        }
        ...
    },
      "users": {
          "user1": {
              "firstname": "robin",
              "email": "robin@example.com",
              "borrowed": {
                  "1234567890": {
                      "book_id": "book1"
                  },
                  "3247829398": {
                      "book_id": "book99"
                  }
              }
          },
          ...
      }
  }
  </code></pre>