【问题标题】:how include embedded Document in rails only query如何在 rails only 查询中包含嵌入的文档
【发布时间】:2018-05-11 11:35:20
【问题描述】:

模型声明由大量字段组成。 在使用唯一功能查询索赔的索赔控制器索引操作中,打印在索引列表中的字段正在从数据库中查询

@claims = @claims.only(:nice_id, :brand_id, etc.. :status).desc(:_id)

嵌入在声明中的“文档”类,许多文档嵌入在声明中。

我需要在结果集的声明中包含文档。需要对我的查询进行哪些更改?

使用 Mongoid 代替 Active Model,

mongoid 版本 3,rails 版本 3.2

【问题讨论】:

  • 是 Document 类 AR 类,如果是,它与 Claims 有什么样的关联?
  • 索赔 embeds_many 文件

标签: ruby-on-rails mongoid mongoid3


【解决方案1】:

嗯,对我来说,在 mongoid 3 上,将关联名称或其别名 (stored_as)(如果有)添加到 only 有效:

@claims = @claims.only(:nice_id, :brand_id, ..., :documents).desc(:_id)

【讨论】:

  • 在索赔模型embeds_many :documents, cascade_callbacks: true 和文档模型embedded_in :claim 中我之前尝试过这个,但是这个脚本对我不起作用
猜你喜欢
  • 2015-04-23
  • 2021-02-21
  • 1970-01-01
  • 2012-08-22
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 2021-03-24
  • 1970-01-01
相关资源
最近更新 更多