Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 8 array passed to create function ? #12

Open
gillettm opened this issue Jan 21, 2018 · 1 comment
Open

Chapter 8 array passed to create function ? #12

gillettm opened this issue Jan 21, 2018 · 1 comment

Comments

@gillettm
Copy link

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.

@StevenJoseph19
Copy link

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.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants