【发布时间】:2020-05-20 17:13:47
【问题描述】:
我目前正在开发一个库存系统,该系统采用 Part Collection 和 Purchase Collection 作为应用程序的主干。每个零件多有相应的采购。即,零件必须具有与其关联的零件 ID、序列号和成本号。我正在将 Meteor.js 与咖啡脚本、玉石和 Graphr 一起使用。我可以单独插入每个集合,但它们似乎没有连接。我已经在两个连接之间设置了链接器,但我对下一步去哪里有点迷茫
这是一个集合的sn-p
购买集合
PurchaseInventory.schema = new SimpleSchema
partId:
type:String
optional:true
serialNum:
type:Number
optional:true
costNum:
type:Number
optional:true
部件集合/模式
Inventory.schema = new SimpleSchema
name:
type:String
optional:true
manufacturer:
type:String
optional:true
description:
type:String
optional:true
零件查询
export getInventory = Inventory.createQuery('getInventory',
$filter: ({ filters, options, params }) ->
if params.filters then Object.assign(filters, params.filters)
if params.options then Object.assign(options, params.options)
return { filters, options , params }
name:1
manufacturer:1
description:1
pic:1
purchase:
partId:1
)
购买查询
export getPurchase = PurchaseInventory.createQuery('getPurchase',
$filter: ({ filters, options, params }) ->
if params.filters then Object.assign(filters, params.filters)
if params.options then Object.assign(options, params.options)
return { filters, options , params }
serial:1
cost:1
date:1
warrentyDate:1
userId:1
)
链接器
//Parts
Inventory.addLinks
purchase:
collection:PurchaseInventory
inversedBy:"part"
//purchases
PurchaseInventory.addLinks
part:
type:'one'
collection:Inventory
field:'partId'
index: true
最后是 Jade/Pug 自动表格
+autoForm(class="inventoryForm" schema=schema id="inventoryInsertForm" validation="blur" type="method" meteormethod="inventory.insert")
.formGroup
+afQuickField(name="name" label="Name")
+afQuickField(name="manufacturer" label="Manufacturer")
+afQuickField(name="description" label="Description")
button#invenSub(type="submit") Submit
重申我的目标是让每个项目都具有指向其相应购买数据的链接。
【问题讨论】:
标签: mongodb meteor coffeescript pug meteor-autoform