Searchlogic 结果与每个关联重复

发布于 2024-09-17 07:28:51 字数 561 浏览 5 评论 0原文

当我链接关联不同表的 searchlogix 条件时,结果会重复。

当我链接 searchlogix 条件查询单个表中的字段时,结果完美。

下面是跨多个表的链接条件的示例(机器属于制造商并且机器属于工具和系统)。

Machine.manufacturer_id_equals(params[:search][:manufacturer]) \
.tools_id_equals(params[:search][:tools]) \
.systems_id_equals(params[:search][:systems]

在此查询中,只应返回 1 个有效结果,但同一行返回 8 次(随着每个新条件搜索不同表,总结果似乎加倍)。

我认为连接、关联等存在问题。

更新:似乎正在返回(重复的)结果。假设有 2 个有效的机器匹配。但是,查询返回与机器相关的每个工具和系统的匹配项。所以如果机器有2个工具和2个系统,则返回4次。

临时修复是对返回的数组调用 uniq,消除重复的结果。然而,这感觉很糟糕,而且几乎肯定不会扩展。

有人可以提供指导吗?谢谢。

When I chain searchlogix conditions that associate different tables, the results duplicate.

When I chain searchlogix conditions querying fields from a single table, the results work perfectly.

Below is an example of chaining conditions across multiple tables (machine belongs to a manufacturer and machine habtm tools and systems).

Machine.manufacturer_id_equals(params[:search][:manufacturer]) \
.tools_id_equals(params[:search][:tools]) \
.systems_id_equals(params[:search][:systems]

In this query, only 1 valid result should be returned but the same row is returned 8 times (the total results seem to double with each new condition searching different tables).

I assume there is so problem with join, associations, etc.

Update: It appears that (repetitive) results are being returned. Let's say there are 2 valid machine matches. However, the query is returning a match for each tool and system that is related to the machine. So if the machine has 2 tools and 2 systems, it is returned 4 times.

The temporary fix is to call uniq on the returned array, eliminating the repetitive results. However, this feels bad and almost certainly won't scale.

Can anyone provide guidance? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文