Sails.js: Missing Waterline Foreign Key Association in MySQL

I am using waterline ORM in sails.js. I have a user model and a model of other coins that maps to the user model.

//coins.js attributes: { name: 'string', // Associations userId: { model: 'user' } } 

The request created for this model,

 CREATE TABLE `coins` (`name` VARCHAR(255) , `userId` INT , `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `createdAt` DATETIME , `updatedAt` DATETIME ) 

The request should contain a foreign key constraint for userId, but it is not. Is there a workaround for this?

+5
source share
1 answer

At present, the waterline does not create foreign key restrictions in the form that you describe. It creates only the corresponding field.

You can use another library instead of Waterline like Sequelize.js, here is a link on how to do this

https://groups.google.com/forum/#!topic/sailsjs/ALMxbKfnCIo

Or you can manually create constraints and an index.

+2
source

All Articles