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
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Typedesign – Prime Four
hannesfritz
42
3.1k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
340
Design in an AI World
tapps
1
250
A designer walks into a library…
pauljervisheath
211
24k
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