Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Created December 13, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseyl/69d9c5f632099a6fe37de2e8fbc422c1 to your computer and use it in GitHub Desktop.
Save alekseyl/69d9c5f632099a6fe37de2e8fbc422c1 to your computer and use it in GitHub Desktop.
virtual attributes example
# DB way
Shipment.scope
.joins(purchase: :product)
.select(["shipments.*","sum(purchases.items_count*products.gross_weight) as gross_weight"])
.group("shipments.id")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment