【发布时间】:2012-11-11 02:57:28
【问题描述】:
我有 3 张桌子:
profiles, users, payment_details
现在,在models/user.rb 我有以下内容:
has_one :profile, :dependent => :destroy
has_one :payment_detail, :dependent => :destroy
在models/profile.rb 我有:
has_one :payment_detail, :through => :user
在models/payment_details.rb 我有:
has_one :profile, :through => :user
然后我有一个 :profile 表单和一个 :payment_details 嵌套表单。
由于某种原因,:payment_details 使用来自 :profiles 的 :id 而不是来自 :profiles 的 :user_id 更新了 :user_id
【问题讨论】:
-
您似乎缺少每个关系的
belongs_to方面。这只是复制粘贴的遗漏吗? -
是的,我在
payment_detail和profile模型中都有belongs_to :user。 -
给我们一个带有表单和控制器的视图。
标签: ruby-on-rails activerecord database-relations