问题
Iam Trying to create authentications using devise with riak as the database. I found a ORM strategy for the same https://github.com/frank06/devise-ripple, it does work all fine except for the part that when i try to register with a email which is already present in the db it does not provide a error message instead it overwrites the present data and updates it. The problem I figured is that ripple deals with .save() differently than active record, ie when active record would throw and error Ripple just overwrites it.
回答1:
Since Riak doesn't have a concept of unique fields, you're going to have to check the uniqueness on the app level of your stack.
The way I'd do it is a quick m/r function or even a search/2i check for the count of documents that have the e-mail value you're validating. Everything above 0 is obviously a failed validation.
回答2:
Depending on how you use your keys, you could have the key set to a hash of the email address.
Checking the existence for that specific entry will be as easy as requesting that specific document, should be a lot faster than a map/reduce or search.
来源:https://stackoverflow.com/questions/7888009/ripple-with-devise