wclr / mongoose-fill

Virtual async fileds for mongoose.js
61 stars 8 forks source link

document#fill does not return a promise #12

Closed gavinaiken closed 8 years ago

gavinaiken commented 8 years ago

This works:

Example.findOne({_id: id})
.exec()
.then(found => {
    found.fill('myRef', (err, filled) => {
        // filled.myRef is filled
    });
});

But this does not:

Example.findOne({_id: id})
.exec()
.then(found => {
    return found.fill('myRef);
})
.then(filled => {
        // filled.myRef is not filled, because the document fill method only takes the callback, it doesn't return a promise.
    });
});

And I do know I can do this:

Example.findOne({_id: id})
.fill('myRef)
.exec()
.then(filled => {
        // filled.myRef is filled
    });
});

but sometimes you have a mongoose document which you want to fill later, not at query time.

(Thanks for the great plugin though, I prefer it to mongoose's populate!)

wclr commented 8 years ago

Ok, I will add it.

wclr commented 8 years ago

Ok, added in 1.5.0 ;)

gavinaiken commented 8 years ago

wow that was quick, thanks! testing...

gavinaiken commented 8 years ago

Works great :)