Also works with new bolt driver
3.2.0 : allow setRelationship & set to be used with simple object and not just Model instance or id
breaking: v3 no longer relies on neo4j id's and sets own id
property if not set in model declaration
const NeoDM = require('neodm');
NeoDM.db.setDB('http://localhost:7474');
NeoDM.db.setLogger(console.log);
const Joi = require('joi');
const Model = NeoDM.Model;
class User extends Model {
static [Model.schema]() {
return {
username: Joi.string()
};
}
}
const johnData = { username: 'john' };
const john = new User(johnData);
yield john.save();
class User extends Model {
static [Model.schema]() {
return {
username: Joi.string()
};
}
}
class Article extends Model {
static [Model.schema]() {
return {
title: Joi.string().default('test'),
author: Model.hasOne(User)
};
}
}
const johnData = { username: 'john' };
const john = new User(johnData);
yield john.save();
const article = new Article({ title: 'hello world', author: john });
yield article.save();
class User extends Model {
static [Model.schema]() {
return {
username: Joi.string()
};
}
}
const johnData = { username: 'john smith' };
const john = new User(johnData);
yield john.save();
const johnFromDB = yield User.find({ username: johnData.username });
const john = new User({ username: 'john' });
yield john.save();
const smith = new User({ username: 'smith' });
yield smith.save();
const users = yield User.find([smith.id, john.id]);
class Author extends Model{
static [Model.schema](){
return {
name:Joi.string()
}
}
afterInit(){
//no return
}
afterInflate(inflatedRelationshipKeys){
return Promise;
}
beforeValidate(){
return Promise;
}
}
better see the tests
-signed gpg 3