Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Created June 26, 2014 20:22
Show Gist options
  • Save jordaaash/a08ba6d427293de2eb2a to your computer and use it in GitHub Desktop.
Save jordaaash/a08ba6d427293de2eb2a to your computer and use it in GitHub Desktop.
Unique validation with LGTM and Bookshelf/Knex
unique = (message) ->
message ?= 'must be unique'
@using (value, attribute, model) ->
query = model.constructor.query()
query.count().where(attribute, value).first()
.then (row) ->
row.count isnt '0'
, message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment