Reputation: 5230
I am using waterline ORM in sails.js. I have a user model and another coins model which associates to the user model.
//coins.js
attributes: {
name: 'string',
// Associations
userId: {
model: 'user'
}
}
The query generated for this model is
CREATE TABLE `coins` (`name` VARCHAR(255) , `userId` INT , `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `createdAt` DATETIME , `updatedAt` DATETIME )
The query should contain foreign key constraint for userId but doesn't. Is there a workaround for this?
Upvotes: 6
Views: 1943
Reputation: 5979
Currently waterline does not create foreign key constraints in the manner you describe. It only creates the associated field.
You can use a different library instead of Waterline such as Sequelize.js here is a link about how to go about doing that
https://groups.google.com/forum/#!topic/sailsjs/ALMxbKfnCIo
Or you can manually create the the constraints and the index.
Upvotes: 3