Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ERD_on_Rails.pdf
Search
ogom
August 08, 2015
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ERD_on_Rails.pdf
ogom
August 08, 2015
More Decks by ogom
See All by ogom
PicoRuby から始めるたのしい電子工作
ogom
0
2.1k
GraphQL Better Errors
ogom
0
400
Osaka RubyKaigi 02
ogom
0
370
Osaka RubyKaigi 01
ogom
0
250
Contributing to GitLab with OSS Gate
ogom
0
640
DojoCon Japan 2017
ogom
0
170
GDStudy Engage
ogom
1
820
Using Immutable.js with React Redux
ogom
0
180
CoderDojo と オープンソース
ogom
2
530
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
The Curse of the Amulet
leimatthew05
1
13k
A designer walks into a library…
pauljervisheath
211
24k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
First, design no harm
axbom
PRO
2
1.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Agile that works and the tools we love
rasmusluckow
331
21k
Transcript
ERD on Rails 68th RubyKansai Takashi Ogomori
ERD on Rails RailsActive RecordͰϞσϧΛૢ࡞Λ͢Δɻ ϞσϧʹΞιγΤʔγϣϯΛઃఆͰ͖Δɻ 2/10
Example Domain ֓ཁʢՁʣ Ϣʔεέʔε ΦϒδΣΫτ ߦࣄཧγεςϜʢΠϕϯτΛ։࠵ͯ͠ɺίϛϡχςΟΛߏஙʣ · ར༻ऀίϛϡχςΟΛઃͰ͖Δɻ ར༻ऀίϛϡχςΟʹೖձͰ͖Δɻ ίϛϡχςΟʹೖձ͢ΔͱϝϯόʔʹͳΔɻ
ίϛϡχςΟΠϕϯτΛ։࠵Ͱ͖Δɻ ΠϕϯτνέοτΛൃߦͰ͖Δɻ ϝϯόʔνέοτೖखͰ͖Δɻ · · · · · · ར༻ऀ, ίϛϡχςΟ, ϝϯόʔ, Πϕϯτ, νέοτ · 3/10
Associations One-to-manyʢ1ରଟʣ Many-to-manyʢଟରଟʣ One-to-Oneʢ1ର1ʣ ̍ͭͷίϛϡχςΟଟͷΠϕϯτΛ։࠵Ͱ͖Δɻ ̍ͭͷΠϕϯτଟͷνέοτΛൃߦ͢Δ͜ͱ͕Ͱ͖Δɻ · · ར༻ऀଟͷίϛϡχςΟʹՃೖ͢Δ͜ͱ͕Ͱ͖Δɻ ϝϯόʔෳͷΠϕϯτʹࢀՃͰ͖Δɻ
· ίϛϡχςΟଟͷར༻ऀΛՃೖͤ͞Δ͜ͱ͕Ͱ͖Δɻ - · ΠϕϯτෳͷϝϯόʔΛࢀՃͤ͞Δ͜ͱ͕Ͱ͖Δɻ - ̍ͭͷίϛϡχςΟ̍ͭͷϙϦγʔΛ࣋ͭ͜ͱ͕Ͱ͖Δɻ · 4/10
Domain Specific Language (DSL) Types આ໌ belongs_to ࢀর has_one ͻͱ͚ͭͩ࣋ͭ
has_many ෳ࣋ͭ has_many through ... Λ௨ͯ͡ෳ࣋ͭ has_one through ... Λ௨ͯ͡ͻͱ͚ͭͩ࣋ͭ has_and_belongs_to_many ࢀরͱෳ࣋ͭ 5/10
Generate 1 One-to-manyʢ1ରଟʣ One-to-Oneʢ1ର1ʣ $ rails generate scaffold group name
$ rails generate scaffold event group:references has_many :events belongs_to :group $ rails generate scaffold policy group:references has_one :policy 6/10
Generate 2 Many-to-manyʢଟରଟʣ Many-to-manyʢଟରଟʣ $ rails generate scaffold user name
$ rails generate scaffold member user:references group:references has_many :members has_many :groups, through: :members has_many :users, through: :members $ rails generate scaffold ticket event:references member:references has_many :tickets has_many :events, through: :tickets has_many :members, through: :tickets 7/10
Generate 3 PolymorphicʢϙϦϞʔϑΟοΫʣ $ rails generate scaffold image imageable:references{polymorphic} name
has_many :images, as: :imageable 8/10
ERD 9/10
10/10