1

I'm using sails.js and mySQL db to build a website. For solving this particular problem, I have thought of pre-defining my ID attribute of my model(taking care of uniqueness by using the timestamp). So once I create a record with the ID that I've defined, I will be able to associate the files(which I upload using JQuery file upload plugin) with this particular record that I created. But I am not sure how to do this in sails.js. Is this possible?

Or can I just define a separate attribute which will have the property unique: true and generate it on front end and pass it over to backend and use this attribute to associate my files.

Community
  • 1
  • 1
A.R.K.S
  • 1,692
  • 5
  • 18
  • 40

1 Answers1

1

If I'm understanding your question correctly, then yes, you can define your own primary key to be used instead of an automatically generated ID.

myAwesomeId: {
    type: 'string',
    unique: true,
    required: true,
    primaryKey: true
},
// other attributes
Fissio
  • 3,748
  • 16
  • 31