变形虫没有克隆所有 :has_many 个关联
amoeba not cloning all :has_many associations
我正在使用变形虫 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。
任何 thoughts/ideas 为什么?
谢谢!
格雷格
我需要将 "enable" 添加到 Censusinfo。下面的例子。感谢 Fabrizio!
class Censusinfo < ActiveRecord::Base
has_many :census_sheets
has_many :census_fields
belongs_to :option
amoeba do
enable
end
#other code......
我阅读了下面的文档link
ActiveRecord: How can I clone nested associations?
您是否应该通过在 class Censusinfo amoeba do enable end
中包含来启用关联的递归复制?
class Censusinfo < ActiveRecord::Base
has_many :census_sheets
has_many :census_fields
belongs_to :option
amoeba do
enable
end
谢谢
法布里齐奥
我正在使用变形虫 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。
任何 thoughts/ideas 为什么?
谢谢!
格雷格
我需要将 "enable" 添加到 Censusinfo。下面的例子。感谢 Fabrizio!
class Censusinfo < ActiveRecord::Base
has_many :census_sheets
has_many :census_fields
belongs_to :option
amoeba do
enable
end
#other code......
我阅读了下面的文档link
ActiveRecord: How can I clone nested associations?
您是否应该通过在 class Censusinfo amoeba do enable end
中包含来启用关联的递归复制?
class Censusinfo < ActiveRecord::Base
has_many :census_sheets
has_many :census_fields
belongs_to :option
amoeba do
enable
end
谢谢
法布里齐奥