New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Within a custom()-method: How to save to a different field within an embedded array? #1219
Comments
Try this, or something similar since I have not tested this, but it should point you in the right direction. AutoformScoopOrders = new Mongo.Collection('autoformscooporders');
autoformScoopOrdersSchema = new SimpleSchema({
customerName: {
type: String
},
// scoopItems Array
scoopItems: {
type: Array,
optional: true,
},
'scoopItems.$': {
type: Object
},
'scoopItems.$.amount': {
type: Number,
},
'scoopItems.$.scoopId': {
type: String,
autoform: { // Foreign-Key Relationship to single Scoops-Object
options: function () {
return Scoops.find().map(function (c) {
return {label: c.name + '( ' + c.price + '$ )', value: c._id};
});
}
}
},
'scoopItems.$.scoopInstance': {
type: Object,
blackbox: true // or define schema keys for instance properties if you want
optional: true,
autoValue: function () {
var theScoopInstanceId = this.siblingField('scoopId');
var theScoopInstance = theScoopInstanceId.isSet && Scoops.findOne(theScoopInstanceId.value);
return _.omit(theScoopInstance, '_id');
},
autoform: {
omit: true;
},
},
}); |
yeah man! Got it going:
Now I'll try to use collection-hooks to update the scoopInstance on update/deletes on the Scoops Object. Thanks a lot for your help! |
No problem, glad it worked! Sent from my iPhone On Sep 28, 2015, at 10:36, MikeSmith12222 notifications@github.com wrote: Hi @serkandurusoy https://github.com/serkandurusoy yeah man! Got it going: 'scoopItems.$.scoopInstance': { Now I'll try to use collection-hooks to update the scoopInstance on Thanks a lot for your help! — |
Hi guys,
I am building a icecream-order-machine where customers place their icecream-orders. 👍
There are 2 Collections:
An example: "Jimmy Hendrix orders 2 scoops of vanilla and 3 scoops of chocolate."
The orderItems are embedded as an array into the ScoopOrder Collection.
Question:
We are doing MongoDB-NoSQL, so the best way to go is to save the scoop._id PLUS the full ScoopObjekt for each ScoopOrder.
How do I do this with Collection2 & Autoform?
This is the code I have so far - I am stuck within the custom() method:
The text was updated successfully, but these errors were encountered: