-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
Mongoid can't handle $pushes into a deeply embedded array. Consider the following code
class A
include Mongoid::Document
embeds_many :bs
end
class B
include Mongoid::Document
embedded_in :a, :inverse_of => :bs
embeds_many :cs
end
class C
include Mongoid::Document
embedded_in :b, :inverse_of => :cs
end
c = C.create(:b => B.create(:a => A.create))
which mongoid translates into this query:
db.as.update(
{"_id": "4c7ae50fc61aeb7190000028", "bs._id": "4c7ae50fc61aeb7190000029"}, {"$push": {"bs.cs":
{"_id": "Whatever"}}})
which fails with "can't append to array using string field name [cs]"
Instead, mongoid should use the $ positional operator (http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator) like so:
db.as.update(
{"_id": "4c7ae50fc61aeb7190000028", "bs._id": "4c7ae50fc61aeb7190000029"}, {"$push": {"bs.$.cs":
{"_id": "Whatever"}}})