You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks, gillettm!
Was stuck on this for awhile. Had this error--
TypeError: Cannot read property 'id' of undefined.
**### This happened on insertEmployee function . If I set the insertEmployee function to use pd._id for all the employees its fine, but using devops._id or acct.id always results in the error .**
I could fix it like this:
function insertTeams(callback) {
Team.create([{
name: 'Product Development'
}, {
name: 'Dev Ops'
}, {
name: 'Accounting'
}], function (error, teams) {
if (error) {
console.log(error);
return callback(error);
} else {
console.info('teams successfully added')
// console.log(pd._id);-->This will also result in 'undefined'
// console.log(devops._id);
// console.log(acct._id);
console.log(teams[0]._id);-->This works.
callback(null, teams[0], teams[1], teams[2]);
}
});
}
However, your solution is the coolest - resolves the error with minimal fuss.
In both insertTeams and insertEmployees :
When the array is passed to create for either Team or Employee, later on, both devops and acct are undefined and pd is an array.
I had to remove the square brackets when create is called for both Team and Employee for later code to work correctly.
The text was updated successfully, but these errors were encountered: