-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added NoteTag model and note_tags table
Added NoteTag model class, note_tags DB table, associations between Note and NoteTag and private / foreign keys.
- Loading branch information
1 parent
ae00fa8
commit 54e517b
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# == Schema Information | ||
# | ||
# Table name: note_tags | ||
# | ||
# note_id :bigint(8) not null, primary key | ||
# k :string default(""), not null, primary key | ||
# v :string default(""), not null | ||
# | ||
# Foreign Keys | ||
# | ||
# note_tags_id_fkey (note_id => notes.id) | ||
# | ||
|
||
class NoteTag < ApplicationRecord | ||
belongs_to :note | ||
|
||
validates :note, :associated => true | ||
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true | ||
validates :k, :uniqueness => { :scope => :note_id } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateNoteTags < ActiveRecord::Migration[7.2] | ||
def change | ||
# Create a table and primary key | ||
create_table :note_tags, :primary_key => [:note_id, :k] do |t| | ||
t.column "note_id", :bigint, :null => false | ||
t.column "k", :string, :default => "", :null => false | ||
t.column "v", :string, :default => "", :null => false | ||
end | ||
|
||
# Add foreign key without validation | ||
add_foreign_key :note_tags, :notes, :column => :note_id, :name => "note_tags_id_fkey", :validate => false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class NoteTagTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |