当我定义用户 has_many 会议时,它会自动创建一个与用户集合相关的“user_id”键/值对。除了我不能使用这个值运行任何 mongo_mapper 发现,没有它返回 nil 或 []。
Meeting.first(:user_id => "1234")
Meeting.all(:user_id => "1234")
Meeting.find(:user_id => "1234")
全部归零。还有其他语法吗?基本上我无法对自动生成的关联 ObjectId 运行查询。
# Methods
class User
include MongoMapper::Document
key :user_name, String, :required => true
key :password, String
many :meetings
end
class Meeting
include MongoMapper::Document
key :name, String, :required => true
key :count, Integer, :default => 1
end
# Sinatra
get '/add' do
user = User.new
user.meetings "foobar") #should read: Meeting.new(:name => "foobar")
user.save
end
get '/find' do
test = Meeting.first(:user_id => "4b4f9d6d348f82370b000001") #this is the _id of the newly create user
p test # WTF! returns []
end