6

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73

1 Answers1

3

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.

Meeker
  • 5,979
  • 2
  • 20
  • 38