Created
May 30, 2016 22:54
-
-
Save keithwhor/12c1bf8a22d201a832a433af2b785f38 to your computer and use it in GitHub Desktop.
Nodal 0.11 Relationships Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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