随着我在 CompoundJS 世界中的进步,我遇到了两种定义模式的方法:
第一的:
var Product = describe('Product', function () {
property('upc', String);
property('name', String);
set('restPath', pathTo.products);
});
第二:
var Schema = require('jugglingdb').Schema;
var schema = new Schema('memory');
var Product = schema.define('Product', {
upc: { type: Number, index: true },
name: { type: String, limit: 150, index: true },
createdAt: { type: Date, default: Date.now },
modifiedAt: { type: Date, default: Date.now }
}, {
restPath: pathTo.products
});
第一个,工作,但看起来像一个旧的设计。第二个,不起作用,但这是根据 JugglingDB 文档的方法。
我应该使用哪一个?为什么第二个对我不起作用?
更新: 这是我使用第二个错误时遇到的错误:
Express
500 TypeError: Cannot call method 'all' of undefined in products controller during "index" action
at Object.index (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\app\controllers\products.js:47:13)
at Array.2 (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:150:28)
at ActionContext.run [as innerNext] (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:103:31)
at Controller.BaseController.next (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\base.js:107:22)
at Controller.protectFromForgery (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\helpers.js:76:21)
at Object.protectFromForgeryHook (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\app\controllers\application.js:3:13)
at Array.1 (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:150:28)
at run (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:103:31)
... snip ...