I notice when using many the foreign key shouldn't be a string because
the foreign key will be wrapped in quotes.
class User
include MongoMapper::Document
many :posts
end
User.first.posts << Post.new()
User.first.posts # => MONGODB app-development.posts.find
({:user_id=>4b04c9ba9a67c268aa000001}, {})
Notice the key isn't wrapped in quotes.
Then we add the foreign key in Post
class Post
include MongoMapper::Document
key :user_id, String, :required => true, :index => true
end
Post.first # => #<Post user_id: "4b04c9ba9a67c268aa000001">
Notice the key IS wrapped in quotes.
User.first.posts # => [ ]
class Post
include MongoMapper::Document
key :user_id, :required => true, :index => true
end
Pull out the String from the key.
Post.first # => #<Post user_id: 4b04c9ba9a67c268aa000001>
User.first.posts # => [ #<Post user_id: "4b04c9ba9a67c268aa000001"> ]
Maybe I'm missing something here but it works now. Thanks to the
logger I noticed 'many' searches for foreign keys without quotes.