Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SailsJS and mySQL custom ID name not working with blue prints

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

like image 337
Pathsofdesign Avatar asked Jan 02 '14 00:01

Pathsofdesign


People also ask

What is waterline in sails JS?

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.

Is sails JS framework?

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.

How does sails JS work?

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.


2 Answers

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
}
like image 81
Rahat Khanna Avatar answered Oct 24 '22 07:10

Rahat Khanna


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.

like image 5
Pathsofdesign Avatar answered Oct 24 '22 05:10

Pathsofdesign