Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def self.reviewable_products_for(user)
- Product.find_by_sql(["
- SELECT DISTINCT
- product.id, product.display_name, product.extended_size, product.description,
- review.body AS review_body, review.id AS review_id, review.ducks AS review_ducks, review.active AS review_active,
- loyalty_rating.title AS loyalty,
- co.created_at AS last_ordered
- FROM product
- JOIN customer_order_line_item coli ON coli.product_id = product.id
- JOIN customer_order co ON co.id = coli.customer_order_id
- LEFT JOIN review ON review.product_id = product.id
- AND review.user_id = ?
- LEFT JOIN loyalty_rating on review.loyalty_rating_id = loyalty_rating.id
- WHERE co.account_id = ?
- ORDER BY co.created_at DESC, product.display_name ASC
- ", user.id, user.account.id])
- end
Add Comment
Please, Sign In to add comment