Hi, I'm currently learning web2py for deployment on Google App Engine,
and I've got a couple of questions about how the datastore works.

Let's say I've got a relational database with students, courses and
enrolments. Enrolments is the join table that allows a many to many
relationship between students and courses. For example:

Students
--------
id
name

Courses
------------
id
title

Enrolments
----------------
student_id
course_id

This allows me to show a list of courses for a student, and a list of
users enrolled on a course, by using join queries. I can order these
lists by the student name, and do pagination too (using LIMIT and
OFFSET).

However, as I understand it, in the Google datastore, you can't do
joins like this. From what I've read you could do it with a
list:reference field, which basically contains a list of IDs like this
1|2|3|4 etc., so the data would look like this:

Student
-----------
id
name
courses

e.g. 1, "John Smith", 1|2|3

Course
----------
id
title
students

e.g. 1, "Physics 101", 4|5|6

(and no enrolments table)

Is that how data has to be modelled using the GAE datastore? If so, is
it possible to do the following:

- paginate the denormalised data, for example show a paginated list of
students on a course?
- have hundreds of IDs in the list:reference field (a course could
have hundreds of students) - or is there an upper limit?

Also, how are updates to these fields handled? For example, remove one
student from a course that has hundreds enrolled? Are there mechanisms
in web2py to handle this?

Also, it would seem that the two list:reference fields would need to
be kept synchronised somehow - if a student is deleted, any course
that they were enrolled on needs to be updated too, which (with my
mind still in relational database mode) would seem to be very
inefficient.

I think what I need is a high-level overview of how data needs to be
designed for the GAE datastore ̣- however as I've found this forum to
be very helpful I thought I'd ask my specific questions here first
before I go off and watch some Google I/O videos.

Any help in me trying to get my head around this is greatly
appreciated!

Many thanks
Dave

Reply via email to