두 필드 id 및 name이있는 Product라는 모델이 있습니다. 나는 발자국을 설치했다. 나는 우체부를 사용하고 로거에서 생성 된 SQL을'id'가 숫자로 시작되는 경우 문자열 'id'가있는 모델에서 GET 요청이 실패합니다. - Trailsjs
SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = N'XX2525';
입니다 요청하기 localhost:3000/product?id=XX2525
를 얻을 때 나는 숫자 localhost:3000/product?id=10XX2525
로 시작하는 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'
}
}
}
}
생성 된 SQL은
입니다SELECT [Product].[ProductCode] AS [id], [Product].[ProductName] AS [name] FROM [dbo].[dimProduct] AS [Product] WHERE [Product].[ProductCode] = 10;
내가 트레일 일인지 또는 후유증인지 확실하지 않지만 내 필드에서 내 필드에 문자열을 정의한 경우 qu tring으로 검색하고 전환을 적용하지 않으려 고합니다. (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"
}
우리에게 산책로, trailpack-sequelize 및 trailpack - hapy 또는 명시 버전을주십시오 – jaumard