Skip to content

Commit 303c997

Browse files
committed
Add user & post models
1 parent 71b7252 commit 303c997

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

app/models/post.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Post < ApplicationRecord
2+
belongs_to :user
3+
end

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User < ApplicationRecord
2+
has_many :posts
3+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreateUsers < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :users do |t|
4+
t.string :name
5+
6+
t.timestamps
7+
end
8+
end
9+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreatePosts < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :posts do |t|
4+
t.string :title
5+
t.references :user, null: false, foreign_key: true
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)