api icon indicating copy to clipboard operation
api copied to clipboard

Add unique flag to field block

Open mingard opened this issue 8 years ago • 6 comments

Some fields such as article title are often required to be unique. Introducing a unique flag should check on matching document field values before accepting/rejecting based on results.

{
  "type": "String",
  "unique": true
}

Alternatively this could be handled in a hook. I will open a ticket for the changes required to achieve this.

mingard avatar May 17 '17 10:05 mingard

Jeez, I was thinking about this yesterday! It could be part of the validation block, perhaps.

eduardoboucas avatar May 17 '17 10:05 eduardoboucas

Yes I prefer the idea of being part of validation.

mingard avatar May 17 '17 10:05 mingard

An alternative would be to hand this off to the storage engine by using a unique index. Or perhaps by adding validation: { unique: true } a unique index is created automatically.

jimlambie avatar May 21 '17 00:05 jimlambie

I like the DB-level concept. Is such a concept supported by all the current Edge DB modules?

Maybe the unique index would be better. Again, if 100% coverage with DBs.

mingard avatar May 21 '17 16:05 mingard

MInd that an index adds load on write operations, you don't necessarily want an index on a field that must be unique. To me this seems more a validation requirement than a DB one.

fra967 avatar May 21 '17 21:05 fra967

Would that increased load be more or less than a pre-save match query on every unique field?

I'm happy with either but perhaps we should test both?

mingard avatar May 22 '17 05:05 mingard