Mongoid and Embedded Relations
Posted on 11 Apr 2011 by Marcus Ahnve
I am experimenting with Mongoid and embedded relations. I have a class A that can have three named 1..1 relations to class B, and I found it quite problematic to get the reverse relationship setup. After specifying class_name and inverse_of everything started working as expected.
1 class B
2
3 include Mongoid::Document
4
5 embedded_in :a, class_name: "A"
6
7 end
8
9 class A
10
11 include Mongoid::Document
12
13 embeds_one :something, class_name: "B", inverse_of: :a
14 embeds_one :completely class_name: "B", inverse_of: :a
15 embeds_one :different, class_name: "B", inverse_of: :a
16
17 end