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
Waterline is a new kind of storage and retrieval engine. It provides a uniform API for accessing stuff from different kinds of databases, protocols, and 3rd party APIs. That means you write the same code to get and store things like users, whether they live in Redis, mySQL, LDAP, MongoDB, or Postgres.
js (or Sails) is a model–view–controller (MVC) web application framework developed atop the Node. js environment, released as free and open-source software under the MIT License. It is designed to make it easy to build custom, enterprise-grade Node. js web applications and APIs.
Sails. js uses Grunt as a build tool for building front-end assets. If you're building an app for the browser, you're in luck. Sails ships with Grunt — which means your entire front-end asset workflow is completely customizable, and comes with support for all of the great Grunt modules which are already out there.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With