1

我已经写了很多 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

我想检索具有与某个值匹配的标识符的子产品的所有产品。

我用这个把自己扭成椒盐卷饼,看起来很容易,但我已经看了太久了。我很感激任何帮助!

4

1 回答 1

0

知道了!

brand.products.joins(:children => :child).where(:children => { :child => { :searchable_identifier.matches => "2136" } } )

这很好用。看到散列连接了吗?这就是让我失望的原因。

于 2010-11-21T03:10:46.787 回答