Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def export
- Product.find_by_sql subset.
- join(products).on(products[:id].eq order_items[:product_id]).
- project(products[Arel.star])
- end
- def subset
- order_items.
- join(colors).on(colors[:id].eq order_items[:color_id]).
- join(orders).on(orders[:id].eq order_items[:order_id]).
- join(addresses).on(addresses[:id].eq orders[:address_id]).
- group(order_items[:product_id]).
- having(order_items[:id].count.gteq 3).
- where(red_colored.and during_this_month)
- end
- def products
- Product.arel_table
- end
- def order_items
- OrderItem.arel_table
- end
- def orders
- Order.arel_table
- end
- def colors
- Color.arel_table
- end
- def addresses
- Address.arel_table
- end
- def red_colored
- colors[:code].eq 'red'
- end
- def during_this_month
- orders[:created_at].gteq Time.now.beginning_of_month
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement