【发布时间】:2011-09-08 21:13:16
【问题描述】:
所以我有一个非常简单的 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! 之类的操作,则不会引发错误,但是一旦操作完成并且您刷新页面或 w/e 更改将被还原。我真的不知道如何进行。有什么帮助吗?
更新:我的更新类不应该有一个 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 的错误。我已恢复为仅将更新的 id 存储在字符串字段而不是 has_one 连接中,一切似乎都很好。
【问题讨论】:
标签: ruby-on-rails mongoid