Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js : Waterline foreign key association missing in MySQL

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?

like image 547
Jaseem Abbas Avatar asked Apr 23 '15 12:04

Jaseem Abbas


1 Answers

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.

like image 87
Meeker Avatar answered Oct 10 '22 13:10

Meeker