Skip to content

Instantly share code, notes, and snippets.

@paneq
Created September 16, 2012 21:53
Show Gist options
  • Save paneq/3734544 to your computer and use it in GitHub Desktop.
Save paneq/3734544 to your computer and use it in GitHub Desktop.
uniqueness by mongo in mongoid
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