【发布时间】:2011-05-13 06:43:27
【问题描述】:
我已经写了很多 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
我想检索具有与某个值匹配的标识符的子产品的所有产品。
我已经用这个把自己变成了一个椒盐脆饼,看起来很容易,但我已经看了太久了。感谢您的帮助!
【问题讨论】:
标签: ruby-on-rails-3 arel