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
300
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.2k
GraphQL Better Errors
ogom
0
400
Osaka RubyKaigi 02
ogom
0
390
Osaka RubyKaigi 01
ogom
0
250
Contributing to GitLab with OSS Gate
ogom
0
650
DojoCon Japan 2017
ogom
0
170
GDStudy Engage
ogom
1
830
Using Immutable.js with React Redux
ogom
0
190
CoderDojo と オープンソース
ogom
2
540
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
370
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
300
GitHub's CSS Performance
jonrohan
1033
470k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
230
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
860
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
Optimising Largest Contentful Paint
csswizardry
37
3.9k
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