Created
June 26, 2014 20:22
-
-
Save jordaaash/a08ba6d427293de2eb2a to your computer and use it in GitHub Desktop.
Unique validation with LGTM and Bookshelf/Knex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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