Object Relational Mapping in ‘Ruby on Rails’

Want to read this story later? Save it in Journal.

class SuperClass    attr_accessor :attribute    ...end
class SubClass < SuperClass    attr_accessor :attribute    ...end
class SubClass < SuperClass    attr_accessor :attribute    ...    def self.create_table
sql = <<-SQL
CREATE TABLE IF NOT EXISTS subclasses (
id INTEGER PRIMARY KEY,
attribute DATATYPE
)
SQL
DB[:conn].execute(sql)
end
end
class SubClass < ActiveRecord::Base...end
The Many-to-Many class relationship
class Grades < ActiveRecord::Base    belongs_to :student
belongs_to :course
end
class Course < ActiveRecord::Base has_many :grades
has_many :students, through: :grade
end
class Student < ActiveRecord::Base has_many :grades
has_many :courses, through: :grade
end

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store