0
所以我有一个非常简单的mongoid类:Mongoid领域没有坚持
class Offer
include Mongoid::Document
field :date, type: DateTime
field :accepted, type: Boolean
scope :accepted, where(accepted: true)
scope :denied, where(accepted: false)
belongs_to :from, class_name: 'User', inverse_of: :from_offers
belongs_to :to, class_name: 'User', inverse_of: :to_offers
belongs_to :update
end
然而,在创建之后,其字段都可以更新。如果我做了像offer.accepted = true,然后offer.save!之类的东西,则不会引发错误,但是一旦完成操作并刷新页面或改变页面就会恢复。我不知道如何继续。任何帮助?
更新:我的更新类不应该有offer_id字段吗?
=> #<Update _id: 4e6933836066250375000033, _type: nil, updated_at: 2011-09-08 21:28:44 UTC, type: "offer", unread: false, topic_id: nil, post_id: nil, user_id: BSON::ObjectId('4e692ad3606625123b000001'), profile_id: nil, commenter_id: BSON::ObjectId('4e692b0b606625037500002a')>
UPDATE2:我在想这可能是has_one的一个bug。我已经恢复到只是将更新的ID存储在字符串字段中而不是has_one连接,并且一切看起来都很好。