Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Uniqueness Enforcement #15

Open
nhahn opened this issue Nov 29, 2014 · 4 comments
Open

Uniqueness Enforcement #15

nhahn opened this issue Nov 29, 2014 · 4 comments

Comments

@nhahn
Copy link

nhahn commented Nov 29, 2014

Hi,

I've been seeing an error when using the sails-memory adapter with models that don't explicitly specify

unique: false

It seems in the enforceUniqueness function in database.js, the call do attrDef.unique is returning a function that returns an empty array rather than a value in the case of not having the unique key explicitly specified in the model.

This causes this line of code

if(!attrDef.unique) continue;

to always evaluate to true, rather than skipping over those attributes that do not have the uniqueness key. It this an issue with the way I am defining my model? Or is it supposed to return a function when there is no key present?

@CWyrtzen
Copy link

CWyrtzen commented Jun 5, 2015

Hi @nhahn is this still an issue?

taoeffect added a commit to taoeffect/sails-memory that referenced this issue Jun 5, 2016
Just because the primary key is unchanged doesn't mean the uniqueness check shouldn't be enforced.

I.e. if we have a table where the primary key is an email or whatever, the uniqueness check here breaks. This PR fixes that.
@taoeffect
Copy link

Just ran across this myself. Sent a fix in PR #30.

@taoeffect
Copy link

Err, looks like my fix broke some tests. Currently investigating.

taoeffect added a commit to taoeffect/sails-memory that referenced this issue Jun 5, 2016
Addresses issue where:

- Model has custom primaryKey (i.e. an email address)
- A uniqueness constraint is placed on another attribute
@taoeffect
Copy link

OK, this is now fixed in #31, and this time all tests are passing! 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants