Created
September 16, 2012 21:53
-
-
Save paneq/3734544 to your computer and use it in GitHub Desktop.
uniqueness by mongo in mongoid
This file contains hidden or 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
class Invitation | |
include Mongoid::Document | |
def self.for(inviter, invited) | |
uniq = {inviter: inviter.id, invited: invited.id} | |
self.collection.update(uniq, {'$set' => uniq}, upsert: true) | |
where(uniq).first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment