Created
May 18, 2016 19:05
-
-
Save Sequoia/d2562cf9ab089fd25ee453bd9dd47678 to your computer and use it in GitHub Desktop.
hasMany relationship
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
/** | |
* @return {Promise} | |
* @fulfill {Array} [{HomeActivityEvent}] array of digest sent events | |
*/ | |
Agent.sendDigestToClients = function(id){ | |
let recordid; | |
return Agent.findById(id) | |
.then(function(agent){ | |
recordid = agent.id; | |
return agent; | |
}) | |
.then(function(agent){ | |
return agent.clients(); | |
}) | |
.then(function(results){ | |
console.log('clients!!'); | |
console.dir(results); //undefined | |
console.log('id', id); | |
}) | |
.then(() => Agent.app.models.User.find({'where': {'agentId': recordid}})) | |
.then(function(results){ | |
results.map(user => console.log(user.agentId)); | |
console.log('users!!'); | |
console.dir(results.length); //1 user | |
}); | |
} |
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
... | |
"relations": { | |
"clients": { | |
"type": "hasMany", | |
"model" : "user", | |
"foreignKey": "agentId" | |
}, | |
} | |
... |
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
{ | |
"name": "user", | |
"plural": "users", | |
"base": "User", | |
"idInjection": true, | |
"properties": { | |
"agentId": { "type": "string", "required": true }, | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment