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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.1k
GraphQL Better Errors
ogom
0
400
Osaka RubyKaigi 02
ogom
0
380
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
540
Featured
See All Featured
Between Models and Reality
mayunak
4
380
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Fireside Chat
paigeccino
42
4k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
440
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
660
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
320
Scaling GitHub
holman
464
140k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
220
Visualization
eitanlees
152
17k
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