Reputation: 5048
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
Upvotes: 6
Views: 2392
Reputation: 4672
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
}
Upvotes: 11
Reputation: 5048
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.
Upvotes: 5