如何使用ThinkingTank和indextank为相关模型建立索引(how to index associated models using thinkingtank and indextank)

编程入门 行业动态 更新时间:2024-10-23 15:30:48
如何使用ThinkingTank和indextank为相关模型建立索引(how to index associated models using thinkingtank and indextank)

我们正在使用thinktank gem,并且无法索引模型关联,甚至是简单的关联。 例如,一个配置文件属于一个机构,它有一个名称 - 我们想要做的事情如下:

class Profile < ActiveRecord::Base #model associations define_index do indexes institution(:name), :as => :institution_name end end

但那不起作用。 这一定很简单 - 我做错了什么?

We are using thinkingtank gem and having trouble indexing model associations, even simple ones. For example, a profile belongs to an institution, which has a name – we would like to do something like:

class Profile < ActiveRecord::Base #model associations define_index do indexes institution(:name), :as => :institution_name end end

but that doesn't work. This must be very simple – what am I doing wrong?

最满意答案

这个问题的一个可能的解决方案是添加一个方法将元素返回给索引。 对于profile.institution.name的情况:

# profile.rb # ... belongs_to :institution # ... define_index do indexes institution_name end def institution_name self.institution.name end # ...

另外,Thinkingtank不支持“::as => ...”语法。

我也建议尝试一下Tanker: https : //github.com/kidpollo/tanker

问候。

阿德里安

a possible solution to this issue would be adding a method returning the element to index. For the profile.institution.name case:

# profile.rb # ... belongs_to :institution # ... define_index do indexes institution_name end def institution_name self.institution.name end # ...

Also the ", :as => ..." syntax is not supported on thinkingtank.

I would also recommend giving a try to Tanker: https://github.com/kidpollo/tanker

Regards.

Adrian

更多推荐

gem,simple,associations,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-07-31 20:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   索引   模型   ThinkingTank   thinkingtank

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!