Below is my schema.
**Payment.js**
var PaymentSchema = new Schema({
customer: {
customerRef: {
type: Schema.ObjectId,
ref: 'Customer'
},
custMemberId : String,
branch : String
},
paymentStatus : String,
payBalance : Number,
deliveryMode : String
});
**Order.js**
var OrderSchema = new Schema({
OrderId : string,
products :[{type : String}],
totalCost : Number
});
**Customer.js**
var Customer= new Schema({
Name : String,
previousOrders :[{
type: Schema.ObjectId,
ref: 'Order']}
});
I have noted down some of the fields in the schema files. My problem is from a payment page,
If I refer to the previous orders of customer, I am not able to access the array previousOrders.
I try
console.log($scope.payment.customer.customerRef.previousOrders);
the output is 'undefined'
PaymentAPI - service
exports.payment = function(req, res, next, id) {
Payment
.findOne({
_id: id
})
.populate('customer.customerRef')
.exec(function(err, payment{
if (err) return next(err);
if (!payment) return next(new Error('Failed to load payment' + id));
req.payment = payment;
next();
});
};
Please let me know , the other possibilities.