Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created September 6, 2011 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeepers/1197658 to your computer and use it in GitHub Desktop.
Save bkeepers/1197658 to your computer and use it in GitHub Desktop.
:in and :from associations in MongoMapper
class List
include MongoMapper::Document
key :user_ids, Array, :typecast => ObjectId
many :users, :in => :user_ids
end
class User
include MongoMapper::Document
# Option 1
many :lists, :from => 'User' # defaults to :user_id
many :lists, :from => 'User', :foreign_key => :owner_ids
# Option 2
many :lists, :from => :owner_ids
many :owned_lists, :from => :owner_ids, :class_name => 'List'
# Option 3
many :lists, :inverse_of => :users
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment