I have 2 models
class Category < ActiveRecord::Base
belongs_to :parent, :class_name => \"Category\"
has_many :children, :class_name => \"Catego
While the operation of joins()
here is pretty smart, the where()
part isn't so clever. AFAIK it doesn't know anything about the joins and really just converts its arguments to strings. As such, try this:
Product.joins(:category=>:parent).where(:parents_categories=>{:id=>1})
In order to avoid bleeding the name used internally by AR to your code, consider using AREL for your query. There have been some excellent railscasts on that subject recently.