loopback icon indicating copy to clipboard operation
loopback copied to clipboard

How can I get including data directly ?

Open fanttm opened this issue 9 years ago • 1 comments

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.)

fanttm avatar Jun 24 '17 09:06 fanttm

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.

stale[bot] avatar Aug 23 '17 14:08 stale[bot]