1
想不通這是爲什麼不工作Mongoid自基準集的has_many不工作
class User
include Mongoid::Document
class Student < User
include Mongoid::Document
....
has_one :parent , class_name: "Parent", inverse_of: :children
class Parent < User
include Mongoid::Document
....
has_many :children, class_name: "Student", inverse_of: :parent
當我試圖通過設置
jane = Student.create!(name: "Jane")
janesParent = Parent.new(name: "Jenny")
janesParent.children.push(jane)
janesParent.save!
我得到這個錯誤的父/子關係
When adding a(n) Student to Parent#children, Mongoid could not determine the
inverse foreign key to set. The attempted key was 'parent_id'.
我做錯了什麼?
P.S我不想嵌入這些想要存儲的ID如果適用的類型。
燁的作品。然而,我想塑造一個父母有很多孩子,一個孩子只有一個父母。即1 .... N關係 – dboyd68