SailsJS蓝图走向干线

时间:2018-05-18 19:38:37

标签: mysql sails.js waterline

我一直在使用SailsJS v0.12开发应用程序。该应用程序按预期工作。但是,对于某些模块,升级到v1.0是有意义的,因为它提供了一些很棒的功能,并且网站暗示(或似乎是这样)升级过程很简单。

事实并非如此。经过一天繁琐的重构后,我成功构建了现有代码并开始研究新模块。关注的问题从这里开始。

我按照之前在 POSTman 中的方式运行了这些功能,但我停止了响应。为了检查单个模型,我尝试使用蓝图。由于没有对任何模型进行任何结构改变,这应该是有效的。但我无法在POST中得到任何回复; GET仍然有效。我退出了休息时间,然后向一个具有一些关联的模型发出GET请求(之前工作正常)。

我得到了这个回复

  

UsageError:无效的populate(s)。细节:无法填充   customer因使用模糊而导致。这是一个单数(“模型”)   关联,这意味着它永远不会引用超过一个关联   记录。因此传递子标准(即作为第二个参数)   此关联不支持.populate()),因为它   一般来说没有任何意义。但这就是麻烦 - 看起来   像某种子标准(或其他)提供的! (注意   仅由omitselect组成的子标准是特殊的    有意义的情况。将来会支持此用法   水线版。)

     

以下是传递的内容:{limit:30}

完整的JSON响应是:

{
    "stack": "UsageError: Invalid populate(s).\nDetails:\n  Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }\n\n    at findRecords (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\blueprints\\actions\\find.js:40:21)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at alwaysAllow (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\policies\\index.js:224:11)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at module.exports (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\cors\\clear-headers.js:14:3)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at sails.router.bind._middlewareType (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\csrf\\index.js:148:11)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at _addResViewMethod (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\views\\res.view.js:372:3)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)",
    "message": "Invalid populate(s).\nDetails:\n  Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }\n",
    "name": "UsageError",
    "code": "E_INVALID_POPULATES",
    "details": "Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }"
}

令人困惑的是,这只发生在本地。蓝图在Zeit.co.上托管的部署(相同代码,双重检查)上完美按预期工作我已经测试了足够多次以推断出这不是我模型中的错误。尽管如此,以下是模型 - BillCustomer

models\Bill.js

module.exports = {

    primaryKey:'id',
    attributes: {
        createdAt: { type: 'number', autoCreatedAt: true, },
        updatedAt: { type: 'number', autoUpdatedAt: true, },

        id:{
            type:'string',
            required:true
        },
        bill_number:{
            type:'string'
        },
        admin_id:{
            type:'string'
        },
        channel:{
            type:'string'
        },
        amount:{
            type:'number'
        },
        discount:{
            type:'number',
            defaultsTo:0
        },
        order_date:{
            type: 'number'
        },
        status:{
            type:'string',
            isIn:['generated', 'settled', 'canceled'],
            defaultsTo:'generated'
        },
        type:{
            type:'string',
            isIn:['dine-in', 'take-away', 'delivery', 'logistics-delivery'],
            required:true
        },
        logisticsPartner:{
            type:'string',
            defaultsTo:'phone'
        },

        //association
        customer:{
            model:'customer'
        },

        store:{
            model:'store'
        },
        orderContents:{
            collection:'billmapping',
            via:'bill'
        },
        transactions:{
            collection:'transaction',
            via:'bill'
        }
    }

};

models\Customer.js

module.exports = {

    attributes: {
        createdAt: { type: 'number', autoCreatedAt: true, },
        updatedAt: { type: 'number', autoUpdatedAt: true, },

        id: { type: 'number', autoIncrement: true}, // <-- for SQL databases
        name:{
            type:'string'
        },
        number:{
            type:'string',
            unique:true
        },
        email:{
            type:'string',
            unique:true
        },
        age:{
            type:'number'
        }
    }
};

这个问题让我把头发拉了8个小时了。任何人都可以提出一些建议或分享一些建议吗?

提前致谢。

0 个答案:

没有答案