【问题标题】:Simultaneous creation of Rails resource and nested resources fails, but not systematically同时创建 Rails 资源和嵌套资源失败,但不系统
【发布时间】:2013-08-29 08:25:33
【问题描述】:

抱歉,标题很奇怪,很难概括。

我有这个基本设置

class Release
  has_many :batches
end

class Batch
  belongs_to :release
end

并且batches 数据库表在外键release_id 上有一个非零约束。

我有一个简单的表单,可以一次性创建发布和第一批:

form_for @release do |f|
  ...
  f.fields_for :batches do |ff|
    ...
  end
end

这在本地以及在生产中的大多数时候都可以完美运行。

在极少数情况下,创建失败是因为批次的release_id 在创建时是nil。这意味着有时设置,有时不设置。在不深入研究 ActiveRecord 的情况下,我最好的猜测是这是一个时间问题。

【问题讨论】:

    标签: ruby-on-rails activerecord nested-forms nested-attributes


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多