-
Notifications
You must be signed in to change notification settings - Fork 928
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
7b05c1c
commit 7f5e597
Showing
5 changed files
with
69 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,12 @@ | ||
class CreateNoteTags < ActiveRecord::Migration[7.2] | ||
def change | ||
# Create a table, primary and foreign keys | ||
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 | ||
|
||
t.foreign_key :notes, :column => :note_id, :name => "note_tags_id_fkey" | ||
end | ||
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 |