title: Ransacker return on related field
body: <p>I am trying to create a custom ransacker that returns a product based upon an attribute within another (related) table. My DB schema is as such:</p>
  
  <pre><code>-------------   --------------------
  |products   |   |product_properties|   ------------
  |-----------|   |------------------|   |properties|
  |name       |---|value             |---|----------|
  |description|   |product_id        |   |name      |
  |etc...     |   |property_id       |   ------------
  -------------   --------------------
  
  class Product &lt; ActiveRecord::Base
    has_many :product_properties
    has_many :properties, through: :product_properties
  
    Property.pluck(:id, :name).each do |id, name|
      ransacker name.to_sym, formatter: -&gt; (value) { value.to_s.downcase } do |parent|
        product_properties = Arel::Table.new(:product_properties)
        Arel::Nodes::InfixOperation.new('AND',
          Arel::Nodes::InfixOperation.new('=',
            product_properties[:property_id], id
          ),
          product_properties[:value]
        )
      end
    end
  end
  
  class ProductProperty &lt; ActiveRecord::Base
    belongs_to :product, inverse_of: :product_properties, touch: true
    belongs_to :property, inverse_of: :product_properties
  end
  
  class Property &lt; ActiveRecord::Base
    has_many :product_properties
    has_many :products, through: :product_properties
  end
  </code></pre>
  
  <p>As you may be able to see I want to use ransack to select all products that have a particular property with a value that matches the predicate passed in through ransack, i.e. if I had a width property I would like to do this</p>
  
  <pre><code>Product.ransack(width_eq: 100).result
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>Product.ransack(product_properties_value_eq: 100, product_properties_property_name_eq: 'width')
  </code></pre>
  
  <p>Am I going along the right tracks, and any help with this would be much appreciated. I have been pulling my hair out over this problem.</p>