Add model Post
This commit is contained in:
parent
4883b21b30
commit
b86d78fac0
|
@ -0,0 +1,5 @@
|
|||
class Post < ApplicationRecord
|
||||
belongs_to :profile
|
||||
|
||||
validates :text, length: { maximum: 200 }
|
||||
end
|
|
@ -1,2 +1,3 @@
|
|||
class Profile < ApplicationRecord
|
||||
has_many :posts
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class CreatePosts < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :posts do |t|
|
||||
t.timestamps
|
||||
t.references :profile, null: false, foreign_key: true
|
||||
t.string :text, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,7 +10,15 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_03_10_092513) do
|
||||
ActiveRecord::Schema.define(version: 2021_03_10_092955) do
|
||||
|
||||
create_table "posts", force: :cascade do |t|
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "profile_id", null: false
|
||||
t.string "text", null: false
|
||||
t.index ["profile_id"], name: "index_posts_on_profile_id"
|
||||
end
|
||||
|
||||
create_table "profiles", force: :cascade do |t|
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
|
@ -20,4 +28,5 @@ ActiveRecord::Schema.define(version: 2021_03_10_092513) do
|
|||
t.string "description"
|
||||
end
|
||||
|
||||
add_foreign_key "posts", "profiles"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
profile: one
|
||||
text: Hello, World!
|
||||
|
||||
two:
|
||||
profile: two
|
||||
text: OMG this is a real microblog!
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Reference in New Issue