Tag: order

基本Rails 3问题:如何对产品进行排序?

我有以下型号: Product: name, shop_id (foreign key), brand_id (foreign key), price Shop: name Brand: name 协会是: Product: belongs_to :shop belongs_to :brand Shop: has_many :products has_many :brands, :through => :products Brand: has_many :products has_many :shops, :through => :products 在ProductsController#list我想获得按商店名称排序的所有产品的列表,然后按品牌名称排序。 我试着做: @products = Product.order(“products.shop.name ASC, products.brand.name ASC”) 但它不起作用(我猜因为products.shop.name在数据库级别不存在)。 这样做的正确方法是什么?