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
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
200
A Tale of Four Properties
chriscoyier
163
24k
Building the Perfect Custom Keyboard
takai
2
790
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
Chasing Engaging Ingredients in Design
codingconduct
0
220
The Mindset for Success: Future Career Progression
greggifford
PRO
0
360
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