首页 > 解决方案 > 弹性宝石。为什么类的比较不正确?

问题描述

我在我的 rails 项目中使用了elasticsearch-modelelasticsearch-rails gems。搜索后,对一堆记录进行分页并调用记录方法。

records = search_results.page(count).records

当我从记录中获取第一条记录时,例如Product类的实体,并与类比较它返回false,但实体类是Product,为什么?

#returns Product entity

records.first

records.first.is_a?(Product)     #=> false
records.first.class == Product   #=> false
records.first.class.name         #=> "Product"

我可以与 class.name == "Product" 进行比较,但为什么类不能正确比较?

编辑:方法记录返回数据库中的记录集合

标签: ruby-on-railsrubyelasticsearch

解决方案


推荐阅读