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

良いアプリケーションは良いデータベースに宿る

Ya-Suzuki
November 27, 2019

 良いアプリケーションは良いデータベースに宿る

2019/11/27 Classi Rails Night

Ya-Suzuki

November 27, 2019
Tweet

More Decks by Ya-Suzuki

Other Decks in Technology

Transcript

  1. class CreateArticles < ActiveRecord::Migration[5.2] def change create_table :articles do |t|

    t.string :title, null: false t.text :content, null: false t.timestamps end end end
  2. class CreateRelationships < ActiveRecord::Migration[5.2] def change create_table :relationships do |t|

    t.references :user, foreign_key: true, null: false t.references :followed, foreign_key: { to_table: :users }, null: false t.timestamps end end end
  3. class User < ApplicationRecord # ڞ௨ͷ৘ใ end class Seller <

    ApplicationRecord has_many :selling_items, dependent: :destroy ɹ# ചΓखʹؔ͢ΔϦϨʔγϣϯ # ചΓखʹؔ͢ΔϏδωεϩδοΫ end class Buyer < ApplicationRecord # ങ͍खʹؔ͢ΔϦϨʔγϣϯ # ങ͍खʹؔ͢ΔϏδωεϩδοΫ end
  4. class User < ApplicationRecord # ڞ௨ͷ৘ใ end class Seller <

    User has_many :selling_items, dependent: :destroy ɹ# ചΓखʹؔ͢ΔϦϨʔγϣϯ # ചΓखʹؔ͢ΔϏδωεϩδοΫ end class Buyer < User # ങ͍खʹؔ͢ΔϦϨʔγϣϯ # ങ͍खʹؔ͢ΔϏδωεϩδοΫ end