【发布时间】:2017-03-12 04:38:16
【问题描述】:
我正在使用 Amoeba gem 克隆一个模型和所有孩子。 gem 运行良好,但有一个例外 - 有一个 :has_many 关联没有被拾取。
我的父模型是选项:
class Option < ActiveRecord::Base
has_many :products, as: :productable, dependent: :destroy
has_many :censusinfos, :autosave => true
belongs_to :rating
accepts_nested_attributes_for :censusinfos
amoeba do
enable
end
# other code.....
产品正在被适当地克隆,但问题出在 :censusinfos。该模型定义为:
class Censusinfo < ActiveRecord::Base
has_many :census_sheets
has_many :census_fields
belongs_to :option
#other code......
CensusField 子项已正确复制,但未克隆 CensusSheet。
任何想法/想法为什么??
谢谢!
格雷格
【问题讨论】:
-
你不应该通过包含在
class Censusinfo`amoeba do enable end` 中来启用recursive copying of associations。我想你发现变形虫听到了吗? stackoverflow.com/questions/6711956/… -
你是对的!没有在 Censusinfo 协会中“启用”变形虫。
-
@Gpnect76 非常感谢。我发布了对您帖子的答案。
标签: ruby-on-rails ruby amoeba-gem