【发布时间】:2014-06-19 17:07:37
【问题描述】:
我有两个模型由一个中间模型加入
class Integration < ActiveBase
has_many :integration_records
has_many :records, through: :intragration_records
end
class IntegrationRecords < ActiveBase
belongs_to :integrations
belongs_to :records
end
class Records < ActiveBase
has_many :integration_records
has_many :integrations, through: :intragration_records
end
现在,IntegrationRecords 有一个默认为 nil 的 JSON 数据列。
我想创建一个集成及其各自的记录并将数据添加到 integration_records 上的数据列
我想过这样的事情,但没有奏效:
Integration.create!(whatever_data).integration_records.create(data: {}).records.create(whatever)
这失败了...我注意到它会自动为
创建一条记录 Integration.create!(whatever_data).integration_records.create(data: {})
所以接下来的想法是:
Integration.create!(whatever_data).integration_records.create(data: {}).records.update(whatever)
没用。帮助别人!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 ruby-on-rails-3.2 has-many-through