Reputation: 33
I'm working with Sequelize, but I'm having trouble to get my requisition's return.
This is what I got so far:
var m = Messagem.findAll({}).then((mensagens)=>{
console.log(mensagens); // i have a reponse :D
return mensagens;
});
console.log(m);
Promise {
_bitField: 2097152,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined,
_boundTo: Messagem }
What am I doing wrong?
Any help is appreciated!
Upvotes: 3
Views: 3533
Reputation: 111288
You cannot return a value from the promise resolution handler
(well, you can, but it will be the result of the resolution or rejection of the promise that is returned by the .then()
method itself, like in this example).
In your case m
is a promise so you need to use it as such. Instead of:
console.log(m);
you have to do:
m.then(console.log);
or this:
console.log(await m);
if you are inside a function declared with the async
keyword.
See this answer for more info about that. See also other answers about promises.
Upvotes: 2