Sails: Feature Request: UNIQUE constraint on multiple columns

Created on 10 Sep 2018  路  6Comments  路  Source: balderdashy/sails

Sails version: 1.0.2
Node version: 10.8.0
NPM version: 6.2.0
DB adapter name: N/A
DB adapter version: N/A
Operating system: Windows 10




Hi, I started a fairly large project with sails.js and in the middle of it I was having trouble because of the lack of this feature.
I need to create composite unique constraint in my models (I know this is possible to create this constraint on DB but I think it is not so genius).
Can you suggest a way or implement this feature to continue my project?
Thanks馃檹

proposal resolved

All 6 comments

@Alirezamohammadi Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

What database / adapter are you using? There may be options available to you depending on your environment :grin:

For example, sails-hook-mongoat looks like adds composite unique unique keys if you're using MongoDB. You may be able to modify it to work in your environment if you're daring enough.

That said, if you're not, set migrations to safe so Sails/Waterline doesn't destroy your schema, create the composite key at the database level and handle errors/exceptions as neccessary.

@texh Thanks, I am using PostgreSQL in my project, is there other way than creating composite keys at the DB level?

@Alirezamohammadi this is definitely on our radar, and @mikermcneil and I have been talking about how this could work, but I don't have a good idea of when it might make it's way into a future release.

As a workaround in the mean time, you might consider making some helpers to handle the logic for creating/updating any records that need special validation like that, and then calling those helpers rather than using .create() and .update() directly in those cases.

I would like to implement this. Any pointers on where to proceed?

@rachaelshaw Thanks for your consideration, I hope this feature will be added soon to the sails js.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radoslavpetranov picture radoslavpetranov  路  4Comments

anissen picture anissen  路  3Comments

Sytten picture Sytten  路  4Comments

svmn picture svmn  路  4Comments

Alirezamohammadi picture Alirezamohammadi  路  4Comments