これもGitHub issueとして報告されました。
Mongoid 2.2.0または2.2.0-stableブランチ(d6ace09c以降)で問題を再現できませんでした。
このコード:offer
が正常に更新されたことを示し、この出力は、制作
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
end
class User
include Mongoid::Document
has_many :from_offers, :class_name => 'Offer', :inverse_of => :from
has_many :to_offers, :class_name => 'Offer', :inverse_of => :to
end
User.delete_all
Offer.delete_all
user1 = User.create
user2 = User.create
user3 = User.create
puts "user1 ID = #{user1.id}"
puts "user2 ID = #{user2.id}"
puts "user3 ID = #{user3.id}"
Offer.create(
:date => Date.today,
:accepted => false,
:from => user1,
:to => user2,
)
ap Offer.first.attributes
Offer.first.update_attributes :accepted => true, :to => user3
ap Offer.first.attributes
:
user1 ID = 4e696a052b58af5dce000001
user2 ID = 4e696a052b58af5dce000002
user3 ID = 4e696a052b58af5dce000003
{
"_id" => BSON::ObjectId('4e696a052b58af5dce000004'),
"date" => 2011-09-08 04:00:00 UTC,
"accepted" => false,
"from_id" => BSON::ObjectId('4e696a052b58af5dce000001'),
"to_id" => BSON::ObjectId('4e696a052b58af5dce000002')
}
{
"_id" => BSON::ObjectId('4e696a052b58af5dce000004'),
"date" => 2011-09-08 04:00:00 UTC,
"accepted" => true,
"from_id" => BSON::ObjectId('4e696a052b58af5dce000001'),
"to_id" => BSON::ObjectId('4e696a052b58af5dce000003')
}