搜索逻辑 +性病

发布于 2024-08-04 12:41:23 字数 743 浏览 6 评论 0原文

尝试实现使用与 STI 关联的搜索逻辑搜索,但遇到问题,它没有选择 STI 记录作为子类,而是选择父类。

例子: <代码>

class Users
end

艺术家类<用户 有很多 :agents, :through => : 代理艺人 端

类代理<用户 有很多 :艺术家, :through => : 代理艺人 结尾

when i do a search for "artist agents company like", it is searching based on the agents as users rather than as agents:

select * from users WHERE users.company LIKE

而不是

select * from users ASagents WHEREagents.company LIKE

想知道我是否可以在 ActiveRecord 类级别预防此问题(例如,在协会中,我在想,如果您可以指定代理将被加载:as=>:agent 或类似的内容),或者如果我需要修补 searchlogic 或我还可以做些什么来完成此任务。

我想到的另一个选项(我害怕这个想法)是在用户表上添加一个字段,其中包含该人的机构列表。例如 users.agency =>机构一名称,机构二名称

Trying to implement a search logic search that uses associations with STI but I’m having a problem where it is not select the STI records as the subclass but the parent.

Example:

class Users
end

class Artist < User has many :agents, :through => :agents artists end

class Agent < User has many :artists, :through => :agents artists end


when i do a search for "artist agents company like", it is searching based on the agents as users rather than as agents:

select * from users WHERE users.company LIKE

rather than

select * from users AS agents WHERE agents.company LIKE

Wondering if I can pre-empt this problem at the ActiveRecord class level (eg in the association I was thinking that if you could specify that the agents would get loaded :as=>:agent or something along those lines), or if I would need to patch searchlogic or what else I could do to accomplish this.

One other option that occurred to me, and I dread the idea, is to add a field on the user table that includes a listing of the person’s agencies. eg users.agencies => Agency One Name,Agency Two Name

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月打碎记忆 2024-08-11 12:41:23

我找到了一个似乎运行良好的解决方案,我在艺术家类上添加了一个命名范围:

命名范围:机构包括,lambda { |c| { :加入=> :代理人,:条件=> { :代理用户 => {:公司=> c } } } }

搜索字段现在称为搜索[艺术家机构包括]

I found a solution that seems to be working well, I added a named scope on the artist class:

named scope :agencies include, lambda { |c| { :joins=> :agents,:conditions => { :agents users => { :company => c } } } }

The search field is now called search[artist agencies include]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文