我有4张桌子:
A has many B
B belong_to A
C has many D
D belong_to C
A has_one C
B has one D
自: 编辑,插入B
row 1
row 2
模型
def self.build_width_invoice(hash1, hash2)
doc = Doc.new(hash1) # hash hash B_attributes
doc.build_C(hash2) # hash hash D_attributes
doc
end
控制器
obj = A.build_width_invoice(hash1, hash2)
obj.save
save to A, B
C, D ok
每个id关系都已填满,但id_D int表B没有值
数据B和D是相同的
我该如何插入?