Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Integrity

Data Integrity

Be confident in your data. Less bugs. Moar happy.

Delivered at hsv.rb - http://www.meetup.com/hsv-rb/events/192571982/

Jay Hayes

July 24, 2014
Tweet

More Decks by Jay Hayes

Other Decks in Programming

Transcript

  1. UIFEBUBT create_table :purchases do |t| t.integer :product_id, null: false t.integer

    :user_id, null: false t.index %i(product_id, user_id), unique: true end
  2. user = User.find(1) product = Product.find(1) Purchase.create(user: user, product: product)

    product.destroy Purchase.last => #<Purchase id: 1, product_id: 1, user_id: 1> _.product => nil but it dead???
  3. user = User.find(1) product = Product.find(1) Purchase.create(user: user, product: product)

    product.delete Purchase.last => #<Purchase id: 1, product_id: 1, user_id: 1> WOMP