Rails:更新两个表之间的id关系

时间:2013-04-07 09:35:12

标签: ruby-on-rails rails-activerecord

我有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是相同的

我该如何插入?

0 个答案:

没有答案