Last active
February 3, 2016 20:47
-
-
Save andrewjmead/1e8a1dc85679a440ed16 to your computer and use it in GitHub Desktop.
Shena - Query Eager Load
This file contains hidden or 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
| // PART ONE - Query todos with user info included | |
| Todo.findAll({include: [User]}).then(function(todos) { | |
| todos.forEach(function (todo) { | |
| console.log(todo.toJSON()); | |
| }); | |
| }, function() {}); | |
| // Printed to screen for each todo | |
| // You can get the username by calling todo.user.userName | |
| // { | |
| // id: 1, | |
| // description: 'Clean yard', | |
| // completed: false, | |
| // createdAt: Wed Feb 03 2016 15: 35: 25 GMT - 0500(EST), | |
| // updatedAt: Wed Feb 03 2016 15: 35: 25 GMT - 0500(EST), | |
| // userId: 1, | |
| // user: { | |
| // id: 1, | |
| // email: 'andrew@example.com', | |
| // userName: 'Andrew Mead', | |
| // createdAt: '2016-02-03 20:35:25.855 +00:00', | |
| // updatedAt: '2016-02-03 20:35:25.855 +00:00' | |
| // } | |
| // } | |
| // PART TWO - Query for all todos whos user has a name of 'Andrew Mead' | |
| Todo.findAll({ | |
| include: [{ | |
| model: User, | |
| where: { userName: 'Andrew Mead' } | |
| }] | |
| }).then(function(todos) { | |
| todos.forEach(function (todo) { | |
| console.log(todo.toJSON()); | |
| }); | |
| }, function() {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment