SlideShare a Scribd company logo
1 of 15
Single Table
Inheritance
http://jyaasa.comCopyright 2016. Jyaasa Technologies.
Hi all,
I am Surya Prasad Siwakoti
Associate Software Engineer
Jyaasa Technologies
http://jyaasa.comCopyright 2016. Jyaasa Technologies.
Objectives
● Introduction to STI (Single Table Inheritance)
● When to use STI
● How to implement STI
● When not to use STI
● Demo
Why Single Table Inheritance
● Avoid Data Redundancy (DRY principle)
● Object Oriented way instead of Database
Relational approach between two objects
● Single table for multiple model
create_table :stylist do
|t|
t.id :integer
t.date :date_of_birth
t.string :first_name
t.string :last_name
t.string :email
t.sign_in_count
:integer
t.string :password
t.string :gender
end
Data Redundancy
create_table :customer do |t|
t.id :integer
t.date :date_of_birth
t.string :first_name
t.string :last_name
t.string :email
t.sign_in_count :integer
t.string :password
t.string :gender
end
class User < ActiveRecord::Base
end
class Stylist < User
end
class Customer < User
end
Object Oriented way instead of Database
Relational approach between two objects
What is Single Table Inheritance?
● STI allows you to create subclasses of a particular database
table.
● Eg: Parent class: user, Child class: stylist, customer
● Using a single table for multiple objects
When to Use STI
When there are two or more than two objects which have
same attributes but different behaviours.
class User < ActiveRecord::Base
end
class Stylist < User
def requested_or_verified?
profile.requested? || profile.verified?
end
end
class customer < User
def habbit_image
return ‘default-photo’ if
habit_image.blank?
end
end
Stylist.new({
first_name: “surya”
})
Stylist.last.first_name
=> “surya”
Customer.new({
first_name: “sarbada”
})
Customer.last.first_name
=> “sarbada”
Benefits of STI
1. Simple approach
● Create a model class eg: stylist
● Inherit from a user
● Create a type field with string data type in user table
2. No more gems
3. OO way
4. Faster query
A single query in one table is enough for retrieving data.
3. DRY Principle
● DRY controller
● No redundant data in table
Drawbacks Of STI
● Tightly coupled parent model
● Changes to the database affects controller and view codes.
● Child class database field should not have too many unique attributes.
● We cannot change object class in runtime. An object life cycle should
finish.
a = Stylist.first
a.type = “Customer”
a.class.name
a.reload!
● Forces to save nullable/empty columns.
a.update_attributes(type:
"ShippingAddress", country: "Spain") #
=> true # but should be false
a.class.name # => "BillingAddress" #
But we wanted ShippingAddress
a.valid? # => true # but should be
false, we ship only to USA and Canada
class Address < ActiveRecord::Base
validates_presence_of :full_name,
:city, :street, :postal_code
end
class BillingAddress < Address
validates_presence_of :country
end
class ShippingAddress < Address
validates_inclusion_of :country,
in: %w(USA Canada)
end
Type Change Drawback
● Arkency Blog. 2016. Single Table Inheritance - Problems and solutions - Arkency
Blog. [ONLINE] Available at: http://blog.arkency.com/2013/07/sti/. [Accessed 20
June 2016].
● FutureLearn. 2016. Refactoring our Rails app out of single-table inheritance.
[ONLINE] Available at: https://about.futurelearn.com/blog/refactoring-rails-sti/.
[Accessed 20 June 2016].
● Eugene Wang. 2016. How (and When) to Use Single Table Inheritance in Rails -
eugenius. [ONLINE] Available at: http://eewang.github.io/blog/2013/03/12/how-and-
when-to-use-single-table-inheritance-in-rails/. [Accessed 20 June 2016].
References
Thank you

More Related Content

Similar to Single table inheritance

Defense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMsDefense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMsVanessa Hurst
 
Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Doria Hamelryk
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENTLori Moore
 
Database Modeling presentation
Database Modeling  presentationDatabase Modeling  presentation
Database Modeling presentationBhavishya Tyagi
 
How to build data accessibility for everyone
How to build data accessibility for everyoneHow to build data accessibility for everyone
How to build data accessibility for everyoneKaren Hsieh
 
Java Basics.pdf
Java Basics.pdfJava Basics.pdf
Java Basics.pdfEdFeranil
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxchristinemaritza
 
Data ops: Machine Learning in production
Data ops: Machine Learning in productionData ops: Machine Learning in production
Data ops: Machine Learning in productionStepan Pushkarev
 
Cassandra Data Modeling
Cassandra Data ModelingCassandra Data Modeling
Cassandra Data ModelingBen Knear
 
Taking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondTaking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondSalesforce Developers
 
GCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxGCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxazida3
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern PerlDave Cross
 
What’s New in Imply 3.3 & Apache Druid 0.18
What’s New in Imply 3.3 & Apache Druid 0.18What’s New in Imply 3.3 & Apache Druid 0.18
What’s New in Imply 3.3 & Apache Druid 0.18Imply
 
Avoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfAvoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfCédrick Lunven
 
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019Vlad Mihalcea
 

Similar to Single table inheritance (20)

Defense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMsDefense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMs
 
Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
 
Database Modeling presentation
Database Modeling  presentationDatabase Modeling  presentation
Database Modeling presentation
 
How to build data accessibility for everyone
How to build data accessibility for everyoneHow to build data accessibility for everyone
How to build data accessibility for everyone
 
Topics-Ch4Ch5.ppt
Topics-Ch4Ch5.pptTopics-Ch4Ch5.ppt
Topics-Ch4Ch5.ppt
 
Topics-Ch4Ch5.ppt
Topics-Ch4Ch5.pptTopics-Ch4Ch5.ppt
Topics-Ch4Ch5.ppt
 
Java Basics.pdf
Java Basics.pdfJava Basics.pdf
Java Basics.pdf
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
 
Data ops: Machine Learning in production
Data ops: Machine Learning in productionData ops: Machine Learning in production
Data ops: Machine Learning in production
 
Cassandra Data Modeling
Cassandra Data ModelingCassandra Data Modeling
Cassandra Data Modeling
 
Machine learning
Machine learning Machine learning
Machine learning
 
Taking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondTaking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and Beyond
 
GCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxGCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptx
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
What’s New in Imply 3.3 & Apache Druid 0.18
What’s New in Imply 3.3 & Apache Druid 0.18What’s New in Imply 3.3 & Apache Druid 0.18
What’s New in Imply 3.3 & Apache Druid 0.18
 
Avoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfAvoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdf
 
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 

More from Jyaasa Technologies (20)

Incident management with jira
Incident management with jiraIncident management with jira
Incident management with jira
 
Extreme programming practices ( xp )
Extreme programming practices ( xp ) Extreme programming practices ( xp )
Extreme programming practices ( xp )
 
The myth of 'real javascript developer'
The myth of 'real javascript developer'The myth of 'real javascript developer'
The myth of 'real javascript developer'
 
Microservices
MicroservicesMicroservices
Microservices
 
Facade pattern in rails
Facade pattern in railsFacade pattern in rails
Facade pattern in rails
 
Scrum ceromonies
Scrum ceromoniesScrum ceromonies
Scrum ceromonies
 
An introduction to bitcoin
An introduction to bitcoinAn introduction to bitcoin
An introduction to bitcoin
 
Tor network
Tor networkTor network
Tor network
 
Collective ownership in agile teams
Collective ownership in agile teamsCollective ownership in agile teams
Collective ownership in agile teams
 
Push notification
Push notificationPush notification
Push notification
 
The Design Thinking Process
The Design Thinking ProcessThe Design Thinking Process
The Design Thinking Process
 
User story
User storyUser story
User story
 
Design sprint
Design sprintDesign sprint
Design sprint
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
OKRs and Actions Overview
OKRs and Actions OverviewOKRs and Actions Overview
OKRs and Actions Overview
 
Vue.js
Vue.jsVue.js
Vue.js
 
Active record in rails 5
Active record in rails 5Active record in rails 5
Active record in rails 5
 
Design Patern::Adaptor pattern
Design Patern::Adaptor patternDesign Patern::Adaptor pattern
Design Patern::Adaptor pattern
 
Association in rails
Association in railsAssociation in rails
Association in rails
 
Web design layout pattern
Web design layout patternWeb design layout pattern
Web design layout pattern
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Single table inheritance

  • 2. Hi all, I am Surya Prasad Siwakoti Associate Software Engineer Jyaasa Technologies http://jyaasa.comCopyright 2016. Jyaasa Technologies.
  • 3. Objectives ● Introduction to STI (Single Table Inheritance) ● When to use STI ● How to implement STI ● When not to use STI ● Demo
  • 4. Why Single Table Inheritance ● Avoid Data Redundancy (DRY principle) ● Object Oriented way instead of Database Relational approach between two objects ● Single table for multiple model
  • 5. create_table :stylist do |t| t.id :integer t.date :date_of_birth t.string :first_name t.string :last_name t.string :email t.sign_in_count :integer t.string :password t.string :gender end Data Redundancy create_table :customer do |t| t.id :integer t.date :date_of_birth t.string :first_name t.string :last_name t.string :email t.sign_in_count :integer t.string :password t.string :gender end
  • 6. class User < ActiveRecord::Base end class Stylist < User end class Customer < User end Object Oriented way instead of Database Relational approach between two objects
  • 7. What is Single Table Inheritance? ● STI allows you to create subclasses of a particular database table. ● Eg: Parent class: user, Child class: stylist, customer ● Using a single table for multiple objects
  • 8. When to Use STI When there are two or more than two objects which have same attributes but different behaviours.
  • 9. class User < ActiveRecord::Base end class Stylist < User def requested_or_verified? profile.requested? || profile.verified? end end class customer < User def habbit_image return ‘default-photo’ if habit_image.blank? end end Stylist.new({ first_name: “surya” }) Stylist.last.first_name => “surya” Customer.new({ first_name: “sarbada” }) Customer.last.first_name => “sarbada”
  • 10. Benefits of STI 1. Simple approach ● Create a model class eg: stylist ● Inherit from a user ● Create a type field with string data type in user table 2. No more gems 3. OO way 4. Faster query A single query in one table is enough for retrieving data. 3. DRY Principle ● DRY controller ● No redundant data in table
  • 11. Drawbacks Of STI ● Tightly coupled parent model ● Changes to the database affects controller and view codes. ● Child class database field should not have too many unique attributes. ● We cannot change object class in runtime. An object life cycle should finish. a = Stylist.first a.type = “Customer” a.class.name a.reload! ● Forces to save nullable/empty columns.
  • 12. a.update_attributes(type: "ShippingAddress", country: "Spain") # => true # but should be false a.class.name # => "BillingAddress" # But we wanted ShippingAddress a.valid? # => true # but should be false, we ship only to USA and Canada class Address < ActiveRecord::Base validates_presence_of :full_name, :city, :street, :postal_code end class BillingAddress < Address validates_presence_of :country end class ShippingAddress < Address validates_inclusion_of :country, in: %w(USA Canada) end Type Change Drawback
  • 13. ● Arkency Blog. 2016. Single Table Inheritance - Problems and solutions - Arkency Blog. [ONLINE] Available at: http://blog.arkency.com/2013/07/sti/. [Accessed 20 June 2016]. ● FutureLearn. 2016. Refactoring our Rails app out of single-table inheritance. [ONLINE] Available at: https://about.futurelearn.com/blog/refactoring-rails-sti/. [Accessed 20 June 2016]. ● Eugene Wang. 2016. How (and When) to Use Single Table Inheritance in Rails - eugenius. [ONLINE] Available at: http://eewang.github.io/blog/2013/03/12/how-and- when-to-use-single-table-inheritance-in-rails/. [Accessed 20 June 2016]. References
  • 14.