Hi there,
I'm trying to create an association between two models using join conditions rather than a foreign key. Does anyone know if this is possible?
For example I want to join products to pricing points. A product has a price and a pricing point has a minimum and maximum amount and a name. Eg. Min = 0, Max = 20, Name = Less than $20. The association between the product is on the price and the min and max.
SELECT *
FROM products
INNER JOIN pricing_points
ON pricing_points.minimum < products.price AND pricing_points.maximum >= products.price
Does this make sense? So I want something like this in my model:
class Product < ActiveRecord::Base
belongs_to :pricing_point, :join => "INNER JOIN pricing_points ON pricing_points.minimum < products.price AND pricing_points.maximum >= products.price"
...
end
Thanks in advance for your help,
Caps