2
我早就發現了早期的新手mongodb錯誤,並且在我應該嵌入它們時創建了很多has_many關係。mongoid將has_many關係轉換爲embeds_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
我通常會遍歷通的所有記錄,這樣做的,但我想象中的命名會是一個問題。所以我不確定我如何才能完成創建臨時模型的這個短小,但是我希望其他一些人犯了同樣的錯誤,並且可能有一個溫和的解決方案?