Ok. So would you like a code of collections, js or htmls? I use MeteorKitchen, so don’t be afraid of some code you could see here.
Maybe I will put some here for now and later on I will add more on your demand:
My collections look like that:
“Customers”:
"name":"customers",
"fields":[
{"name":"name", "title":"Business Name","required":true, "exportable":true},
{"name":"contact_name", "title":"Contact Name","required":true, "exportable":true},
{"name":"email","title":"Email","type":"email","exportable":true},
{"name":"business_address","title":"Business Address","input":"textarea","show_in_dataview":false,"exportable":true},
{
"name": "currency",
"title":"Currency",
"required":"required",
"input":"select",
"lookup_query": {
"name":"currency",
"collection":"currency",
"filter":{}
},
"lookup_field":"name",
"lookup_key":"_id",
"show_in_dataview":false,
"show_in_read_only_form":false,
"exportable":true
},
{
"name":"currencyName",
"title":"Currency",
"show_in_insert_form": false,
"show_in_update_form": false,
"exportable": true
}
],
"owner_field":"ownerId",
"roles_allowed_to_read": ["owner"],
"roles_allowed_to_update":["owner"],
"roles_allowed_to_delete":["owner"]
},
“Invoices”:
{
"name":"invoices",
"fields":[
{
"name":"invoiceNumber",
"title":"Invoice Number",
"default":"{{nextinvoiceNumber}}",
"required":true,
"show_in_read_only_form": false,
"show_in_insert_form":true,
"exportable":true
},
{
"name":"date_issued",
"title":"Issued",
"type":"date",
"format":"DD-MM-YYYY",
"input":"datepicker",
"default":"today",
"required":true,
"show_in_read_only_form": true,
"show_in_insert_form":true,
"exportable":true
},
{
"name":"date_due",
"title":"Due",
"type":"date",
"format":"DD-MM-YYYY",
"input":"datepicker",
"required":true,
"show_in_read_only_form": true,
"show_in_insert_form":true,
"exportable":true
},
{
"name": "customerId",
"title": "Customer",
"input": "select",
"lookup_query": {
"name": "customers",
"collection": "customers",
"filter": {}
},
"lookup_field": "name",
"lookup_key": "_id",
"show_in_dataview":false,
"show_in_insert_form":false,
"show_in_read_only_form": false,
"exportable": false
},
{
"name": "customerName",
"title": "Customer",
"show_in_insert_form": false,
"show_in_update_form": false,
"show_in_read_only_form": true,
"exportable": true
},
{
"name": "totalAmount",
"title":"Amount",
"type":"float",
"show_in_insert_form": false,
"show_in_read_only_form": true,
"show_in_update_form": false,
"exportable": true
},
],
"owner_field": "ownerId",
"roles_allowed_to_read": ["owner"],
"roles_allowed_to_update": ["owner"],
"roles_allowed_to_delete": ["owner"],
"before_insert_code": "if(!doc.totalAmount) doc.totalAmount = 0;",
},
On the server side I do:
Meteor.publish("invoice_editss", function(invoiceId) {
return Invoices.find({_id:invoiceId,ownerId:this.userId}, {transform:function(doc) { var customer = Customers.findOne({_id: doc.customerId }); if(customer)doc.customerName = customer.name; return doc; }});
});
Meteor.publish("customerss", function() {
return Customers.find({ownerId:this.userId}, {});
});
Than on the client side I do:
Meteor.subscribe("customerss"),
Meteor.subscribe("invoice_editss", this.params.invoiceId)
and that:
customerss: Customers.find({}, {}),
invoice_editss: Invoices.findOne({_id:this.params.invoiceId}, {transform:function(doc) { var customer = Customers.findOne({_id: doc.customerId }); if(customer)doc.customerName = customer.name; return doc; }}),
And on my site “invoice_editss” is seen as Object and “customerss” as LocalCollection.cursor.
I would like to put some data from those two into my client-html page.
I do sth like that:
{{invoice_editss.customerName}}
And that code gives me the name of actual customer.
But I want take an email or address of that customer.
@corvid Should I put it in js or html?