1
我是很新的MongoDB和我使用西納特拉和mongomapper與以下設置更新嵌入文檔的值:Mongomapper嵌入文檔「無法序列化對象」錯誤
class TeamMember
include MongoMapper::Document
key :name, String, :required => true
many :team_member_projects
end
class TeamMemberProject
include MongoMapper::EmbeddedDocument
key :date, Date, :required => true
one :project
end
class Project
include MongoMapper::Document
key :name, String, :required => true
end
的修改代碼:
team_member = TeamMember.find(params[:team_member])
project = Project.find(params[:project])
date = Date.parse(params[:date])
tm_project = TeamMemberProject.new(:project => project, :date => date)
team_member.push(:team_member_projects => tm_project)
team_member.save
,但我得到的錯誤.push
行:
BSON::InvalidDocument at /project/add
Cannot serialize an object of class TeamMemberProject into BSON.
我沒有正確聲明我的嵌入式文檔嗎?或者還有另一種更新嵌入式文檔的方式,我不知道。我試圖使用方法:http://mongomapper.com/documentation/plugins/modifiers.html#push
我注意到同樣的事情......可能是一個錯誤。我會在github上報告該項目的一個,看看他們說了些什麼。 –
我不確定這是一個錯誤。修飾符只是簡單的,方便MongoDB修飾符的包裝。修飾符甚至不更新Ruby中的相關文檔,他們直接進入數據庫。所以,「.push」不會意識到MongoMapper關聯。 'team_member.push(:team_member_projects => tm_project.to_mongo)'雖然可以工作。 –