【发布时间】:2012-08-04 13:12:14
【问题描述】:
不久前我犯了早期的新手 mongodb 错误,并在我应该嵌入它们的时候创建了很多 has_many 关系。
我的问题是我现在如何将我的记录从多态 has_many 场景转换为 embeds_many?
#Place.rb
has_many :images, as: :imageable, dependent: :destroy, autosave: true
#Image.rb
belongs_to :imageable, polymorphic: true
到 =>
#Place.rb
embeds_many :images, as: :imageable
#Image.rb
embedded_in :imageable, polymorphic: true
我通常会遍历所有记录并这样做,但我想命名会是一个问题。因此,我不确定如何在不创建临时模型的情况下完成此任务,但我希望其他一些人也犯了同样的错误并可能有一个温和的解决方案?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongoid embedded-resource mongoid3