Skip to content

Commit

Permalink
Merge pull request #44 from hieuhv07/189/model_address
Browse files Browse the repository at this point in the history
189: create model address
  • Loading branch information
N-Viet-ruby-dev authored Aug 27, 2019
2 parents 8c58496 + ee2fb81 commit 1e69b1d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Address < ApplicationRecord
belongs_to :area

validates :name, presence: true
end
1 change: 1 addition & 0 deletions app/models/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Area < ApplicationRecord
belongs_to :location
has_many :address, dependent: :destroy

scope :newest, -> { order created_at: :desc }

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20190819045358_create_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateAddresses < ActiveRecord::Migration[5.2]
def change
create_table :addresses do |t|
t.string :name
t.references :area, index: true, foreign_key: true

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "addresses", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.bigint "area_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["area_id"], name: "index_addresses_on_area_id"
end

create_table "areas", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.bigint "location_id"
Expand Down Expand Up @@ -112,6 +120,7 @@
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "addresses", "areas"
add_foreign_key "areas", "locations"
add_foreign_key "rooms", "locations"
add_foreign_key "rooms", "users"
Expand Down

0 comments on commit 1e69b1d

Please sign in to comment.