[SOLVED] Getting an error "second item is not correct" for the exercise Create Many Records with model.create()

[SOLVED] Getting an error "second item is not correct" for the exercise Create Many Records with model.create()
0.0 0

#1
var createManyPeople = function(arrayOfPeople, done) {
  arrayOfPeople = [{name: 'John', age: 23, favoriteFoods:['Burger, Pizza']}, 
                 {name: 'Howard', age: 33, favoriteFoods:['Pasta, Sandwich']}];
  Person.create(arrayOfPeople, function(err, data) {
    if(err) {
      return done(err);
    }
      else {
        return done(null, arrayOfPeople);
      }
  });
}
  

Can anyone tell me whats the problem?


#2

I think favoriteFoods is supposed to be an array of foods, so it should be ['Burger', 'Pizza'], etc.


#3

Tried that, still getting the same error.


#4

I think I got it. You’re not supposed to assign to the arrayOfPeople variable. The tests will do that for you. The second argument for the last done() call should also be data, not arrayOfPeople.


#5
var createManyPeople = function(arrayOfPeople, done) {
  Person.create([
    {name: 'John', age: 23, favoriteFoods:['Burger', 'Pizza']}, 
    {name: 'Howard', age: 33, favoriteFoods:['Pasta', 'Sandwich']}], function(err, data) {
    if(err) {
      return done(err);
    } 
    else {
      return done(null, data); 
    }
  });
}

Still getting the same error. :confused:


#6

Try passing arrayOfPeople as the first argument for Person.create (don’t make a new array)


#7

Oh yes. That worked. I didn’t have to make any custom data. The tests do it automatically. Just passed arrayOfPeople as the first argument and it worked! Thank you. :slight_smile: