[phase-5]added category model and modified term model
This commit is contained in:
parent
be33f1f6af
commit
96155a9665
3
app/models/glossary_category.rb
Normal file
3
app/models/glossary_category.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class GlossaryCategory < ActiveRecord::Base
|
||||
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
|
||||
end
|
@ -1,2 +1,3 @@
|
||||
class GlossaryTerm < ActiveRecord::Base
|
||||
belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id'
|
||||
end
|
||||
|
7
db/migrate/002_create_glossary_categories.rb
Normal file
7
db/migrate/002_create_glossary_categories.rb
Normal 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
|
5
db/migrate/003_add_category_to_glossary_terms.rb
Normal file
5
db/migrate/003_add_category_to_glossary_terms.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddCategoryToGlossaryTerms < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_reference :glossary_terms, :category, foreign_key: true
|
||||
end
|
||||
end
|
9
test/unit/glossary_category_test.rb
Normal file
9
test/unit/glossary_category_test.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user