搜索逻辑 +性病
尝试实现使用与 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 endclass 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个似乎运行良好的解决方案,我在艺术家类上添加了一个命名范围:
命名范围:机构包括,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]