2

I upgraded my sails from rc4 to rc7 today, and the unique constraint on my model stopped working. note that in rc4 it used to work perfectly. and sails-mongo version on both versions i tried is: "sails-mongo": "^0.10.0-rc5"

Model attribute:

    emailAddress: {
        type: 'email',
        required: true,
        unique: true
    },

any issues?

2 Answers2

1

As already stated it's a bug in waterline/sails-mongo

I however advise against setting syncable to true as it was set to false by the developers for a reason (the github bug report explains more, also already stated igor)

If you require uniqueness you can just create an index in the DB manually. Not a great solution if you're deploying to different environments, but as a temporary work around it'll do.

http://docs.mongodb.org/manual/tutorial/create-a-unique-index/

After all, we're using an RC for a piece of software at version 0.10, this kind of thing should be expected.

mtjburton
  • 11
  • 3
0

Although it's month old, just came here from Google, so for the reference, it is apparently known issue (check here for details: https://github.com/balderdashy/sails-mongo/issues/152)

As It's mentioned there, you can quick-fix this by setting

syncable = true

though that might imply some other problems (auto-migrating on no-sql databases)

igor
  • 56
  • 5
  • Having this same issue now, in 2015, with Sails v11, anybody else? – edencorbin Oct 21 '15 at 15:49
  • @edencorbin try setting `migrate: 'safe',` in your `config/model.js` file. Test this in your dev environment before you do this in production! More info here: http://sailsjs.org/documentation/concepts/models-and-orm/model-settings – igor Oct 21 '15 at 18:27