我已经写了很多 AREL 声明,但我对这个声明束手无策。这是我的情况:
class Product < AR::Base
has_many :parents, :class_name => "ProductLink", :foreign_key => :to_product_id
has_many :children, :class_name => "ProductLink", :foreign_key => :from_product_id
# has an attribute called "identifier"
end
class ProductLink < AR::Base
belongs_to :parent, :class_name => "Product", :foreign_key => :from_product_id
belongs_to :child, :class_name => "Product", :foreign_key => :to_product_id
end
我想检索具有与某个值匹配的标识符的子产品的所有产品。
我用这个把自己扭成椒盐卷饼,看起来很容易,但我已经看了太久了。我很感激任何帮助!