Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def self.reviewable_products_for(user)
  2. Product.find_by_sql(["
  3. SELECT DISTINCT
  4. product.id, product.display_name, product.extended_size, product.description,
  5. review.body AS review_body, review.id AS review_id, review.ducks AS review_ducks, review.active AS review_active,
  6. loyalty_rating.title AS loyalty,
  7. co.created_at AS last_ordered
  8. FROM product
  9. JOIN customer_order_line_item coli ON coli.product_id = product.id
  10. JOIN customer_order co ON co.id = coli.customer_order_id
  11. LEFT JOIN review ON review.product_id = product.id
  12. AND review.user_id = ?
  13. LEFT JOIN loyalty_rating on review.loyalty_rating_id = loyalty_rating.id
  14. WHERE co.account_id = ?
  15. ORDER BY co.created_at DESC, product.display_name ASC
  16. ", user.id, user.account.id])
  17. end
Add Comment
Please, Sign In to add comment