Skip to content

adrianpatania/rails4_callback_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example:

2.2.4 :006 > Product.create(name: ‘product1’, total: 10, price: 10.2)

  (0.3ms)  begin transaction
 SQL (0.9ms)  INSERT INTO "products" ("name", "total", "price") VALUES (?, ?, ?)  [["name", "product1"], ["total", 10], ["price", 10.2]]
  (0.6ms)  commit transaction
=> #<Product id: 1, name: "product1", total: 10, price: #<BigDecimal:7fa0fb90cc18,'0.102E2',18(36)>>

2.2.4 :003 > Order.create(product: Product.first, total: 4)

 Product Load (0.2ms)  SELECT  "products".* FROM "products"  ORDER BY "products"."id" ASC LIMIT 1
  (0.3ms)  begin transaction
 SQL (1.8ms)  INSERT INTO "orders" ("product_id", "total") VALUES (?, ?)  [["product_id", 1], ["total", 4]]
 SQL (0.2ms)  UPDATE "products" SET "total" = ? WHERE "products"."id" = ?  [["total", 6], ["id", 1]]
  (0.6ms)  commit transaction
=> #<Order id: 1, product_id: 1, total: 4>

2.2.4 :004 > Product.first

 Product Load (1.5ms)  SELECT  "products".* FROM "products"  ORDER BY "products"."id" ASC LIMIT 1
=> #<Product id: 1, name: "product1", total: 6, price: #<BigDecimal:7fa0fc17dbb8,'0.102E2',18(36)>>

About

Callback example for rails 4

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published