這甚至可能嗎?更改Mongoid班級名稱中產
我有一個名爲Magazine
的mongoid類,也有一些關聯,我想重新命名爲Publication
。問題是我已經有一羣已經制作雜誌,問題和文章的用戶。
原始Magazine
型號:
class Magazine
# 1. Include mongoid stuff
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
# 2. Define fields
field :title, type: String
field :description, type: String
field :live, type: Boolean, default: false
field :show_walkthrough, type: Boolean, default: true
# 3. Set attributes accesible
attr_accessible :title, :description, :live, :show_walkthrough, :cover_image_attributes, :logo_image_attributes
# 4. Set slug
slug :title
# 5. Set associations
belongs_to :user
has_many :issues, dependent: :delete, autosave: true
has_one :foreword, :as => :articleable, :class_name => 'Article', dependent: :delete, autosave: true
embeds_one :cover_image, :as => :imageable, :class_name => 'Image', cascade_callbacks: true, autobuild: true
embeds_one :logo_image, :as => :imageable, :class_name => 'Image', cascade_callbacks: true, autobuild: true
# 6. Accepting nested attributes
accepts_nested_attributes_for :cover_image, :allow_destroy => true
accepts_nested_attributes_for :logo_image, :allow_destroy => true
# 7. Set validations
validates_presence_of :title, :description, :cover_image, :logo_image
end
我知道我可以在類的名稱更改爲Publication
,然後在MongoDB的做db.magazines.renameCollection("publications")
,但協會不跟隨。
有什麼建議嗎?
這真的不可能嗎?正如我所看到的,我基本上只需要更改關係名稱以及集合名稱。但我不知道該怎麼做。 –