[phase-5]added category model and modified term model

This commit is contained in:
Toru Takahashi 2018-05-06 16:45:27 +09:00 committed by TAKAHASHI,Toru
parent be33f1f6af
commit 96155a9665
5 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,3 @@
class GlossaryCategory < ActiveRecord::Base
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
end

View File

@ -1,2 +1,3 @@
class GlossaryTerm < ActiveRecord::Base class GlossaryTerm < ActiveRecord::Base
belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id'
end end

View File

@ -0,0 +1,7 @@
class CreateGlossaryCategories < ActiveRecord::Migration[5.1]
def change
create_table :glossary_categories do |t|
t.string :name
end
end
end

View File

@ -0,0 +1,5 @@
class AddCategoryToGlossaryTerms < ActiveRecord::Migration[5.1]
def change
add_reference :glossary_terms, :category, foreign_key: true
end
end

View File

@ -0,0 +1,9 @@
require File.expand_path('../../test_helper', __FILE__)
class GlossaryCategoryTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end