Skip to content

Instantly share code, notes, and snippets.

@fahim
Created November 3, 2011 22:12
Show Gist options
  • Save fahim/1337950 to your computer and use it in GitHub Desktop.
Save fahim/1337950 to your computer and use it in GitHub Desktop.
def used_promotion_credits(order)
p = PromotionCredit.arel_table
o = Order.arel_table
if order.user.anonymous?
user_condition = o[:email].eq order.email
else
user_condition = o[:user_id].eq order.user_id
end
PromotionCredit.includes(:order).where(p[:source_id].eq(promotion_id), o[:state].eq(Order::FINALIZED_STATES), user_condition)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment