从活跃的 record/postgres 迁移到 mongodb/mongoid 但我不能 create/save
Migrating from active record/postgres to mongodb/mongoid and I cannot create/save
我在 mongoid 中有以下模型(即,以前在活动记录中)。尝试保存产品项目组和项目选择选项,但我 运行 没有方法“all_of” error.And 我刚开始使用 mongoid/mongobd 和 ROR。
class ProductItemGroup
include Mongoid::Document
include Mongoid::Timestamps
store_in database: "cnc_product_ms"
field :name, localize: true
field :description, localize: true
field :product_item_selection_type, type: String
embeds_one :item_selection_option
has_and_belongs_to_many :service_categories
field :service_category_ids, type: Array
end
class ItemSelectionOption
include Mongoid::Document
include Mongoid::Timestamps
include SimpleEnum::Mongoid
store_in database: "cnc_product_ms"
as_enum :selection_type,multiple: 1, single: 2
as_enum :mandatory_selection_type, atleast_one: 1, many: 2
field :selection_type, type: Integer
field :selection_mandatory, type: Boolean, default: false
field :mandatory_selection_type, type: Integer
embedded_in :product_item_group
end
controller /form
class ProductItemGroupForm < ApplicationForm
attr_accessor(:product_item_group)
def create
@product_item_group = ProductItemGroup.new(params)
@product_item_group.save!
end
end
保存!,我 运行 出现以下错误
NoMethodError: undefined method `all_of' for #<Class:0x00007fd96afea600>
from /Users/90srebel/.rvm/gems/ruby-2.6.4/gems/activerecord-6.0.3.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
知道问题了。我正在关闭这个问题。
我做错的是,
我在 product_item_group 模型中声明了 has_and_belongs_to_many 但忘记在 service_category 模型中声明相同的东西。傻
我在 mongoid 中有以下模型(即,以前在活动记录中)。尝试保存产品项目组和项目选择选项,但我 运行 没有方法“all_of” error.And 我刚开始使用 mongoid/mongobd 和 ROR。
class ProductItemGroup
include Mongoid::Document
include Mongoid::Timestamps
store_in database: "cnc_product_ms"
field :name, localize: true
field :description, localize: true
field :product_item_selection_type, type: String
embeds_one :item_selection_option
has_and_belongs_to_many :service_categories
field :service_category_ids, type: Array
end
class ItemSelectionOption
include Mongoid::Document
include Mongoid::Timestamps
include SimpleEnum::Mongoid
store_in database: "cnc_product_ms"
as_enum :selection_type,multiple: 1, single: 2
as_enum :mandatory_selection_type, atleast_one: 1, many: 2
field :selection_type, type: Integer
field :selection_mandatory, type: Boolean, default: false
field :mandatory_selection_type, type: Integer
embedded_in :product_item_group
end
controller /form
class ProductItemGroupForm < ApplicationForm
attr_accessor(:product_item_group)
def create
@product_item_group = ProductItemGroup.new(params)
@product_item_group.save!
end
end
保存!,我 运行 出现以下错误
NoMethodError: undefined method `all_of' for #<Class:0x00007fd96afea600>
from /Users/90srebel/.rvm/gems/ruby-2.6.4/gems/activerecord-6.0.3.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
知道问题了。我正在关闭这个问题。 我做错的是, 我在 product_item_group 模型中声明了 has_and_belongs_to_many 但忘记在 service_category 模型中声明相同的东西。傻