如果'id'以一个数字开始,GET请求在string'id'的模型上失败 – Trailsjs

我有一个名为产品的模型,有两个字段ID和名称。 我已经安装了脚印。

'use strict' const Model = require('trails/model') /** * @module Product * @description TODO document Model */ module.exports = class Productextends Model { static config (app, Sequelize) { return { store: 'db', options: { schema: 'dbo', tableName: 'dimProduct', timestamps: false, classMethods: { //If you need associations, put them here associate: (models) => { } } } } } static schema (app, Sequelize) { return { id: { type: Sequelize.STRING, allowNull: false, primaryKey: true, field: 'ProductCode' }, name: { type: Sequelize.STRING, field: 'ProductName' } } } } 

当我使用localhost:3000/product?id=XX2525和GET请求localhost:3000/product?id=XX2525在logging器中生成的sql是

 SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = N'XX2525'; 

如果我对一个以localhost:3000/product?id=10XX2525开头的id做同样的查询,则生成的sql是

 SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10; 

我不知道如果这是一个痕迹的事情或一个续集的东西,但如果我有我的领域定义为我的模型中的string我希望查询作为特林search,而不是应用任何转换。 该错误看起来像(001CAR是我的数据库中的第一个ID):

 { "name": "SequelizeDatabaseError", "message": "Conversion failed when converting the varchar value '1CAR' to data type int.", "parent": { "message": "Conversion failed when converting the varchar value '1CAR' to data type int.", "code": "EREQUEST", "number": 245, "state": 1, "class": 16, "serverName": "db", "procName": "", "lineNumber": 1, "sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;" }, "original": { "message": "Conversion failed when converting the varchar value '1CAR' to data type int.", "code": "EREQUEST", "number": 245, "state": 1, "class": 16, "serverName": "db", "procName": "", "lineNumber": 1, "sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;" }, "sql": "SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;", "isBoom": true, "isServer": true, "data": null, "output": { "statusCode": 500, "payload": { "statusCode": 500, "error": "Internal Server Error", "message": "An internal server error occurred" }, "headers": {} } } 

我的package.json依赖关系是,我正在运行节点v6.11.5

 "dependencies": { "ejs": "^2.5.7", "express": "^4.16.2", "tedious": "^2.0.0", "trailpack-express": "^2.0.3", "trailpack-footprints": "^2.0.0", "trailpack-repl": "v2-latest", "trailpack-router": "v2-latest", "trailpack-sequelize": "^2.0.0", "trails": "v2-latest" } 

你遇到了一个已经被这个PR https://github.com/trailsjs/trailpack/pull/44修复的bug,但是这个修复并没有被部署在npm上。

trailpack-express v2.0.6现在有这个修复,更新它,你不应该有问题了