Skip to content

Instantly share code, notes, and snippets.

@keithwhor
Created May 30, 2016 22:54
Show Gist options
  • Save keithwhor/12c1bf8a22d201a832a433af2b785f38 to your computer and use it in GitHub Desktop.
Save keithwhor/12c1bf8a22d201a832a433af2b785f38 to your computer and use it in GitHub Desktop.
Nodal 0.11 Relationships Example
module.exports = (function() {
'use strict';
const Nodal = require('nodal');
const User = Nodal.require('app/models/user.js');
const Sport = Nodal.require('app/models/sport.js');
const Avatar = Nodal.require('app/models/avatar.js');
const Post = Nodal.require('app/models/post.js');
const UserSport = Nodal.require('app/models/user_sport.js');
// Always join child (has parent_id) to parent
Avatar.joinsTo(User); // one:one
Post.joinsTo(User, {multiple: true}); // many:one
// Creating many:many involves a reference table
UserSport.joinsTo(User, {multiple: true});
UserSport.joinsTo(Sport, {multiple: true});
return true;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment