Skip to content

Commit

Permalink
migrated to n:m relation, solved #28
Browse files Browse the repository at this point in the history
  • Loading branch information
akuchinke committed Nov 9, 2017
1 parent c78a674 commit 48e7c7e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/paper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Paper < ActiveRecord::Base
belongs_to :author
has_and_belongs_to_many :authors
validates :title, presence: true
validates :venue, presence: true
validates :year, presence: true, numericality: { only_integer: true }
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20171109163613_create_papers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def change
t.string :title
t.string :venue
t.integer :year
t.references :author, index: true, foreign_key: true


t.timestamps null: false
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20171109193956_join_papers_and_authors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class JoinPapersAndAuthors < ActiveRecord::Migration
def change
create_join_table :authors, :papers
end
end
10 changes: 6 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171109163613) do
ActiveRecord::Schema.define(version: 20171109193956) do

create_table "authors", force: :cascade do |t|
t.string "first_name"
Expand All @@ -21,15 +21,17 @@
t.datetime "updated_at", null: false
end

create_table "authors_papers", id: false, force: :cascade do |t|
t.integer "author_id", null: false
t.integer "paper_id", null: false
end

create_table "papers", force: :cascade do |t|
t.string "title"
t.string "venue"
t.integer "year"
t.integer "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "papers", ["author_id"], name: "index_papers_on_author_id"

end

0 comments on commit 48e7c7e

Please sign in to comment.