I’m trying to send a order with a child order line to my insert method, but the child order line is being inserted as empty object.
The data I’m sending looks like this:
{
"orderLines":
[ {"description":"d1","quantity":0,"unitPrice":0,"lineValue":0,"isNewLine":true,"createdAt":"2016-02-12T10:47:02.240Z"}],
"createdAt":"2016-02-12T10:47:02.222Z",
"deliveryAddress1":"o1"
}
But the mongo record ends up looking like this - there is an order line in the array, but it is an empty record:
{
"_id": "s9xvSnH2HemvKZ287",
"orderLines": [
{}
],
"createdAt": "2016-02-12T10:47:02.222Z",
"deliveryAddress1": "o1"
}
I’m calling the method like this:
// call the method for upserting the data
Orders.methods.insert.call({
orderId: orderId,
data: order
}, (err, res) => {
if (err) {
sAlert.error(err.message);
} else {
sAlert.success("Save successful");
FlowRouter.go("/");
}
});
The ValidatedMethod looks like this:
Orders.methods.insert= new ValidatedMethod({
name: 'Orders.methods.insert',
validate(args) {
var schemaContext = Schemas.OrderSchema.namedContext("OrderForm");
schemaContext.validate(args.data);
},
run(args)
{
console.log("order", JSON.stringify(args.data));
return Orders.insert(args.data);
}
});
And finally the schema looks like this:
Schemas.OrderSchema = new SimpleSchema({
notes: {
type: String,
optional: true
},
deliveryAddress1: {
type: String,
optional: true
},
orderLines: {
type: [Object],
optional: true
},
createdAt: {
type: Date,
optional: false,
label: "Date created"
}
});
Is there anything obviously wrong? I’ve been banging my head against this for hours!