My background with designing data stores comes from Core Data on iOS, which supports properties having a one-to-many relationship with another entity.
I’m working on an App Engine project which currently has three entity types:
User, which represents a person using the app.Project, which represents a project. AUsermay be associated with many projects.Post, which is the main content behind aProject. AProjectmay have many posts.
Currently, User has a property, projects, that is a one-to-many relationship to Project entities. Project has a property, posts, that is a one-to-many relationship to Post entities.
In this case, is Datastore’s Reference Property or NDB’s Structured Property better for the job (and how are the two conceptually different)? Is there a better way to structure my data?
By reference property you probably mean Key Property. This is a reference to another datastore entity. It is present in both db and ndb APIs. Using these, you can model a many to one relationship by pointing many entities to the key of another entity.
Structured property is a completely different beast. It allows you to define a data structure, and then include it within another entity.
Here’s an example from the docs where you include multiple addresses for a single contact:
For your specific application I’d recommend using NDB (it’s always best to use the latest version of the api available), with the following:
Post model included under Project model as a repeated structured property.
Users include a repeated KeyProperty that contains the keys of the Projects they have permissions to.
To make it a bit more complex, you can create a another model to represent projects and permissions/roles, and then include that as a repeated structured property within the user model.
The main reason you want to hang on to the keys, is to keep the data accessible in light of HRDs eventual consistency.
Let me know if you need any more help on this.
EDIT:
To clarify, here’s the proposed structure:
Models:
User model should contain User-Project-Mapping as repeated structured property.
Project model should contain Post as repeated structured property.
User-Project-Mapping only needs to contain Key reference to the Project and relevant permissions representation.
Since this sounds like a commercial project, if you’d like further help with this, I’ll gladly consult for you. Hope you have enough to succeed!