Created
September 6, 2011 14:16
-
-
Save bkeepers/1197658 to your computer and use it in GitHub Desktop.
:in and :from associations in MongoMapper
This file contains 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 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