loopback
loopback copied to clipboard
How can I get including data directly ?
Description/Steps to reproduce
CartItem.find({
where: {
"user_id": userId
},
include: [
"variations",
{
relation: "listing",
scope: {
include: [{
relation: "photos",
scope: {
order: "priority"
}
},
{
relation: "seller",
scope: {
field: ["id", "first_name"]
}
},
"stock"
]
}
}
]
}, (err, cartItems) => {
console.log('cartItems: ', cartItems);
var itemsBySeller = [];
cartItems.forEach(function(item) {
console.log(item);
console.log('item.listing_id: ', item.listing_id, item.id, item.last_updated, item['listing']());
// var sellerId = item.listing.seller.id;
// if (!itemsBySeller[sellerId]) itemsBySeller[sellerId] = [];
// itemsBySeller[sellerId].push(item);
});
var cart = {
user_id: userId,
cart_items: itemsBySeller
};
return cb(null, cart);
})
Expected result
After I get 'cartItems', I want to get 'listing' data of each cart_item, but I found that item['listing'] is a function type and I must execute this function, then I can get the 'listing' data.
How can I get listing data directly ? (No need to execute function.)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.