ruby-on-rails - 从活动记录/postgres 迁移到 mongodb/mongoid,我无法创建/保存
问题描述
我在 mongoid 中有以下模型(即,以前在活动记录中)。尝试保存产品项目组以及项目选择选项,但我没有遇到任何方法“all_of”错误。而且我是使用 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 模型中声明相同的东西。愚蠢的
推荐阅读
- javascript - 如何使用带有 Cypress 的 writeFile 正确发送数据
- console - 如何在 Windows cmd 中禁用跟踪
- javascript - 在 href 点击时调用 Ajax
- firebase - 使用 Cloud Functions 将元标记添加到 SPA html 页面
- rest - API 中的登录和注册请求
- r - mapdist (datDist %>% select(from, to), mode = mode) 中的错误:is.character(from) 不是 TRUE
- paypal - PayPal 使用 JS SDK 省略了稍后付款按钮
- python - 如何在 Pyqt5 中使用 multiprocessing.Queue 和 pyqtgraph?
- visual-studio-code - 如何摆脱 VS-Code 编辑器中的 TS 问题/错误消息?
- vba - 转换为数字表示