Create a gist now

Instantly share code, notes, and snippets.

@kyanny /mm.rb
Created Nov 28, 2016

What would you like to do?
gem 'activemodel', '4.2.7.1'
require 'active_model'
require 'mongo_mapper'
require 'byebug'
require 'logger'
logger = Logger.new(STDOUT)
logger.level = :info
MongoMapper.setup(
{
'development' => {
'host' => '127.0.0.1',
'port' => 27017,
'database' => 'testing',
}
},
'development',
logger: logger
)
class User
include MongoMapper::Document
one :membership
end
class Membership
include MongoMapper::Document
belongs_to :user
end
class WrapUser < User
end
wrap_user = WrapUser.create!
membership = Membership.create!(user: wrap_user)
wrap_user.reload
MongoMapper.connection.logger.level = :debug
p wrap_user.membership
Owner

kyanny commented Nov 28, 2016

$ ruby mm.rb
D, [2016-11-29T03:07:28.346264 #81803] DEBUG -- : MONGODB (0.3ms) testing['memberships'].find({:wrap_user_id=>BSON::ObjectId('583c72606200b03f8b000001')}).limit(-1)
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment