Skip to content
Snippets Groups Projects
Commit 8c2fe2f4 authored by Giovanne Marcelo's avatar Giovanne Marcelo
Browse files

add subject relationship

parent 3126015f
No related branches found
No related tags found
No related merge requests found
module Filterable
extend ActiveSupport::Concern
included do
has_many :subjects, through: :subject_relations, dependent: :destroy
has_many :subject_relations, as: :subjectable, dependent: :destroy
end
end
......@@ -38,6 +38,7 @@ class LearningObject < ApplicationRecord
include Scoreable
include Thumbnailable
include Taggable
include Filterable
include Highlights
# *current_user* create learning object
......
class Subject < ApplicationRecord
has_many :subject_relations
validates_presence_of :name
end
class SubjectRelation < ApplicationRecord
belongs_to :subject
belongs_to :subjectable, polymorphic: true
validates_presence_of :subjectable, :subject
end
class CreateSubjectRelations < ActiveRecord::Migration[5.0]
def change
create_table :subject_relations do |t|
t.references :subject, foreign_key: true, index: true
t.references :subjectable, polymorphic: true, index: true
t.timestamps null: false
end
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class SubjectRelationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment