Skip to content

Instantly share code, notes, and snippets.

@airy
Created May 12, 2011 22:31
Show Gist options
  • Save airy/969604 to your computer and use it in GitHub Desktop.
Save airy/969604 to your computer and use it in GitHub Desktop.
Mongoid HATBM with string keys
class Profile
include Mongoid::Document
# ....
belongs_to :user
key :user_id
alias :to_s :_id
has_and_belongs_to_many :following, :class_name => 'Profile', :inverse_of => :followers
has_and_belongs_to_many :followers, :class_name => 'Profile', :inverse_of => :following
# ....
end
class User
include Mongoid::Document
# ....
field :nick
key :nick
alias :to_s :_id
# ....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment