简体   繁体   English

兰萨克(Ransack)寻找远处的桌子?

[英]Ransack search for far away tables?

I want to search orders by tags, but tags are associated with customers.... is it possible to do that with Ransack? 我想按标签搜索订单,但是标签与客户相关联。...是否可以使用Ransack进行搜索?

Order.rb Order.rb

Class Order < ActiveRecord::Base
belongs_to :customer
 ....

Customer.rb Customer.rb

Class Customer < ActiveRecord::Base
has_many :orders
has_many :customers_tags
has_many :tags, through: :customers_tags
 ....

Tag.rb Tag.rb

Class Tag < ActiveRecord::Base
has_many :customers_tags
has_many :customers, through: :customers_tags
 ....

Yes, you can search through multiple associations. 是的,您可以搜索多个关联。 Just reference them as you would in the association name (plural for has_many , singular for belongs_to ). 刚才提到他们为你在联想的名称将(复数为has_many ,奇异的belongs_to )。

So in your example, searching for a field fieldname , you would use: 因此,在您的示例中,搜索字段fieldname ,您将使用:

customer_tags_fieldname_cont

(Replace fieldname with whatever field you want to search.) (用您要搜索的任何字段替换fieldname 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM