diff --git a/app/models/glossary_category.rb b/app/models/glossary_category.rb new file mode 100644 index 0000000..b48306a --- /dev/null +++ b/app/models/glossary_category.rb @@ -0,0 +1,3 @@ +class GlossaryCategory < ActiveRecord::Base + has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id' +end diff --git a/app/models/glossary_term.rb b/app/models/glossary_term.rb index 778725a..645b6f0 100644 --- a/app/models/glossary_term.rb +++ b/app/models/glossary_term.rb @@ -1,2 +1,3 @@ class GlossaryTerm < ActiveRecord::Base + belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id' end diff --git a/db/migrate/002_create_glossary_categories.rb b/db/migrate/002_create_glossary_categories.rb new file mode 100644 index 0000000..7e67a73 --- /dev/null +++ b/db/migrate/002_create_glossary_categories.rb @@ -0,0 +1,7 @@ +class CreateGlossaryCategories < ActiveRecord::Migration[5.1] + def change + create_table :glossary_categories do |t| + t.string :name + end + end +end diff --git a/db/migrate/003_add_category_to_glossary_terms.rb b/db/migrate/003_add_category_to_glossary_terms.rb new file mode 100644 index 0000000..8084512 --- /dev/null +++ b/db/migrate/003_add_category_to_glossary_terms.rb @@ -0,0 +1,5 @@ +class AddCategoryToGlossaryTerms < ActiveRecord::Migration[5.1] + def change + add_reference :glossary_terms, :category, foreign_key: true + end +end diff --git a/test/unit/glossary_category_test.rb b/test/unit/glossary_category_test.rb new file mode 100644 index 0000000..9e8e198 --- /dev/null +++ b/test/unit/glossary_category_test.rb @@ -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