Ruby/Rails syntax
  • Index
  • chap 1
  • chap 2
  • chap 3
  • chap 4
  • Enterprise Rails - big picture
  • Nokogiri
  • ActiveRecord - 進階功能
  • pack & unpack
  • performance
  • rails engine
  • jsonb / json / hstore
  • Deploy
  • Polymorphism/Polymorphic Associations
  • relationship
  • rvm / ENV
  • Auth
  • DB related
  • TODO N+1
  • SQL view
  • module
  • api + create-react-app
  • ONE_LINE
  • Delete & destroy association
Powered by GitBook
On this page
  • jsonb
  • PSQL search
  • Delete & destroy for association

Was this helpful?

ONE_LINE

Previousapi + create-react-appNextDelete & destroy association

Last updated 5 years ago

Was this helpful?

jsonb

jsonb = [1]avoids reparsing, [2]supports indexing, [3] no key ordering

hstore = [1]not allow a nested structure, [2]store as strings, require type coercion

jsonb is better than hstore

PSQL search

index = [1]use b tree, [2]avoid sequential scan

GIN (Generalized Inverted Index) = [1]use for array or hash, [2] build value -> where

Delete & destroy for association

  1. delete 沒有 dependent: :destroy只清空*_id

  2. delete 有 dependent: :destroy皆刪除record

  3. destroy 不論有無dependent: :destroy皆刪除record

destroy(*id)
destroy_all()
https://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails