-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
Hello,
I'm using mongo (1.3.1), mongoid (4.0.0), moped (2.0.2), rails (4.1.1), ruby 2.1.5p273
This story involves two objects used to build a tree of Steps, with embedded Links documents.
Links are stored in an array within their Step, as embedded documents. Each Link contains a pointer to a step_id.
Here are the minimal objects that can reproduce the behaviour :
class DemoStep include Mongoid::Document field :name, type: String embeds_many :demo_links end
class DemoLink include Mongoid::Document field :label, type: String embedded_in :demo_step belongs_to :next, class_name: 'DemoStep' end
I create two of these Steps for the demo and confirm that s1 and s2 have no Link for now :
s1 = DemoStep.create id: 1, name: "Step 1" s2 = DemoStep.create id: 2, name: "Step 2" s1.demo_links => [] s2.demo_links => []
Finally, I add a Link inside the freshly created
1
, its
attribute fed with
s2
. The Link is popping exactly as expected, and accessing its
next
relation seems correct too :
l = s1.demo_links.create label: "Linking s1 to s2", next: s2
=> #<DemoLink _id: 54920d89626f620958000000, label: "Linking s1 to s2", next_id: 20>
s1.demo_links
=> [#<DemoLink _id: 54920d89626f620958000000, label: "Linking s1 to s2", next_id: 20>]
l.next
=> #<DemoStep _id: 20, name: "Step 2">
But surprise! s2 suddenly receives something for its
links
relation:
s2.demo_links
=> #<DemoLink _id: 54920d89626f620958000000, label: "Linking s1 to s2", next_id: 20>
Even stranger, the collection is not an array but just a link. The Link I just created and added to
s1
pointing to
s2
now corrupted
s2{{`}} itself too.