Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
:in and :from associations in MongoMapper
class List
include MongoMapper::Document
key :user_ids, Array, :typecast => ObjectId
many :users, :in => :user_ids
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment