0

I have a query to db that returns me data and List of objects. The query is done using StrongLoop.

app.models.Individual.findById(id, {
  include: ['languages']
}, function(err, individual) {
  console.log(individual);
}

How can I iterate over List of languages? console.log(individual) returns this JSON

{
  firstname: 'Aarti',
  lastname: 'SHAH',
  id: 1,
  languages: 
   List [
     { name: 'English', flag: 'gb', id: 1 },
     { name: 'German', flag: 'de', id: 2 } ] 
}

I have tried to print individual.languages and it returned

{ [Function]
  _receiver: 
   { firstname: 'Aarti',
     lastname: 'SHAH',
     id: 1,
     languages: List [ [Object], [Object] ],
  _scope: 
   { where: { individualId: 1 },
     collect: 'language',
     include: 'language' },
  _targetClass: 'Language',
  getAsync: [Function],
  build: [Function: build],
  create: [Function: bound ],
  updateAll: [Function: updateAll],
  destroyAll: [Function: destroyAll],
  findById: [Function: bound ],
  findOne: [Function: findOne],
  count: [Function: count],
  destroy: [Function: bound ],
  updateById: [Function: bound ],
  exists: [Function: bound ],
  add: [Function: bound ],
  remove: [Function: bound ] }
Black
  • 9,541
  • 3
  • 54
  • 54
  • `for(var i=0; i – bitifet Jun 27 '16 at 11:06
  • I have run both and first one returned 4 times undefined and second one individual.languages.map is not a function. I have updated question with results of console.log(individual.languages); – Black Jun 27 '16 at 11:47
  • The solution was to use toJson() function. Definitelly not duplicate question as @Bergi marked – Black Jun 27 '16 at 13:10

0 Answers0