ruby on rails - Rails4 order by column alias in joins group -
i want have slugs of categories in descendent order of number of products per category (the category slug category witht products first , ones without products last) i rails 3.2 query category. joins("left outer join products on products.category_id = categories.id"). select('count("products"."id") products_count'). group("categories.slug"). order("products_count desc"). select("categories.slug") worked. after upgrading, an activerecord::statementinvalid: pg::undefinedcolumn error, saying column products_count doesn't exist ...and_id = categories.id group categories.slug order products_c... how should fix it? order not recognize aliases. quick fix: category. joins("left outer join products on products.category_id = categories.id"). group("categories.slug"). order('count("products"."id") desc'). select("categories....