SailsJS and mySQL custom ID name not working with blue prints

时间秒杀一切 提交于 2019-12-22 06:32:57

问题


I created a new model in SailsJS with a custom id name as the primary key. I'd like to utilize the blue prints routes that come with SailsJS but when I try to go to /name/1 I get the error below.

ER_BAD_FIELD_ERROR: Unknown column 'id' in 'where clause'

It appears that Sails is still looking for the default table name 'id' instead of my new custom id. Any ideas on how to get Sails to realize my changes?

Thank you


回答1:


Go to your model definition and add the autoPK:false at last.

module.exports = {

  schema:'true',
  attributes: {
    propertyName: { type:"string", required:true, unique: true }
  },
  autoPK:false
}



回答2:


Okay I looked through SailsJS src and found in node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js on line 37 that checks for the property 'autoPK'. This property is set to true by default and looks for the field 'id'. By setting 'autoPK: false' in my model it will check to see if you have set a custom Primary Key and will use that instead. All Fixed.



来源:https://stackoverflow.com/questions/20874858/sailsjs-and-mysql-custom-id-name-not-working-with-blue-prints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!