Closed omarimayerswalker closed 9 years ago
When I console.log(vendor) it returns the object as expected but if I console.log(vendor.id) I get undefined.
console.log(vendor)
console.log(vendor.id)
var Vendor = require("../db/connection").models.Vendor; var Market = require("../db/connection").models.Market; module.exports = { marketSearch: function(req, res){ var userSub = req // this is working console.log(userSub + " " + Vendor) // this returns Soupergirl + [object SequelizeModel:vendor] Vendor.findAll({ where: {name: userSub }}).then(function(vendor){ console.log(vendor.id) }) } }
console.log(vendor) returns:
It's because findAll returns an array of records, even if that array contains one thing. If you just want the ID of the first one, you'd need vendor[0].id. Make sure your variables names make sense!
findAll
vendor[0].id
When I
console.log(vendor)
it returns the object as expected but if Iconsole.log(vendor.id)
I get undefined.console.log(vendor)
returns: