adam-cowley / neode

Neo4j OGM for Node.js
MIT License
394 stars 72 forks source link

Documentation for creating/working with Schemas/Models having multiple labels. #28

Closed purplemana closed 6 years ago

purplemana commented 6 years ago

Hi,

After searching and comparing a lot of ORM/OGM wrappers around Neo4j, I came across this and it looks fantastic, just the right bunch of APIs and very close to the Neo4J concepts.

I am working on a project where for authentication, I need to support users from various authentication modes, e.g. Email/Password, Ldap, Oauth etc. For this, I have decided to use labels to identify the type, e.g. :User:Email, :User:Ldap, :User:OAuth etc. Looking at the code I can see that it is possible to set labels as an array on the Model. Maybe I missed this in the documentation.

Could you please point me to some examples related to defining a Schema which associates with multiple users? I see that schemas extend, and my user graph should be ideally extendible, e.g.

  1. Any User must have id, email and name.
  2. A User:Email will also have password.
  3. A User:Ldap will have domain and username.
  4. A Oauth user might have oauth specific properties like refreshtoken.

What would be the best way to model this using Neode?

Thanks!

hellopat commented 6 years ago

Hey @purplemana ,

I was able to get this done by doing the following:

instance.with({
  Team: Team,
  ['Affiliation:Division']: Affiliation.division,
  ['Affiliation:Conference']: Affiliation.conference,
})

instance.create('Affiliation:Conference', spec(conference))

This created a node with labels :Affiliation & :Conference

purplemana commented 6 years ago

Thanks @hellopat! I was gonna close this, went through the code to find it out, but my approach is different. I wish there was a way for the generic with methods approach to also take care of extensions, but I guess I can live with this.

How I did this -

instance.model(Models.User, UserSchema);
// Now extend User to EmailUser
instance.extend(Models.User, Models.EmailUser, EmailUserSchema);

Closing this issue.